[英]What is wrong with query Mysql?
有一个简单的SQL查询:
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
我收到此错误消息:
> # 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
您需要将方括号括起来:
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`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.