简体   繁体   中英

What is wrong with query Mysql?

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

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`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM