我怎样才能在sql中修复此语法错误?

时间:2014-05-10 16:10:53

标签: mysql sql syntax-error

SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
AS total_assets
ORDER BY account_name
  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,在第3行的'account_ LIMIT 0,30'的total_assets顺序附近使用

3 个答案:

答案 0 :(得分:1)

删除AS total_assets

SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
ORDER BY account_name

答案 1 :(得分:1)

你的别名错误。

SELECT account_name ,sum(total_balance) from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
AS total_assets
ORDER BY account_name

应该是

SELECT account_name ,sum(total_balance) AS total_assets
from transaction 
where account_name IN('cash','a/r','supplies','prepaid','land','gold')
ORDER BY account_name

答案 2 :(得分:0)

as total_assets移到select子句中。这用于定义列别名:

select account_name, sum(total_balance) as total_assets
from transaction 
where account_name in ('cash', 'a/r', 'supplies', 'prepaid', 'land', 'gold')
order by account_name;