1

There is an trivial SQL query:

SELECT enterprise_invoces.AC_name, 
enterprise_invoces.AC_id, 
enterprise_invoces.AC_code, 
ABS(SUM(IF(AT_amount>0, AT_amount, 0)) AS debit,
ABS(SUM(IF(AT_amount <0, AT_amount, 0)) AS credit 
    FROM account_transactions 
    INNER JOIN enterprise_invoces ON enterprise_invoces.AC_id = account_transactions.AT_code

I get this error message:

> # 1064 - You have an error in the request. Check the MySQL version documentation for correct syntax near 'FROM account_transactions INNER
> JOIN enterprise_invoces ON enterprise_invoces.AC' on line 1

1 Answer 1

4

You need to close brackets:

SELECT enterprise_invoces.AC_name, 
  enterprise_invoces.AC_id, 
  enterprise_invoces.AC_code, 
  ABS(SUM(IF(AT_amount>0, AT_amount, 0))) AS debit,  --here
  ABS(SUM(IF(AT_amount <0, AT_amount, 0))) AS credit  -- here
FROM account_transactions 
JOIN enterprise_invoces 
  ON enterprise_invoces.AC_id = account_transactions.AT_code
 GROUP BY enterprise_invoces.AC_name,
          enterprise_invoces.AC_id,
          enterprise_invoces.AC_code   -- there should be corresponding `GROUP BY`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.