MySQL查询中的错误在哪里?

时间:2012-09-03 05:59:33

标签: mysql sql

运行此MySQL查询时出现以下错误。我的问题在哪里?

  

#1064 - 您的SQL语法出错;查看与MySQL服务器版本对应的手册,以便在第19行的'INT)LIMIT 0,30'附近使用正确的语法。

select tran_date, tran_id,  
    sum(case account_id when 'M0003' then (cr_amt) else 0 end) as cr_sm,  
    sum(case account_id when 'M0003' then (dr_amt) else 0 end) as dr_sm,  
    sum(case account_id when 'M0003' then (balance) else 0 end) as bal_sm,  
    sum(case account_id when 'MD001' then (cr_amt) else 0 end) as cr_cdnw,  
    sum(case account_id when 'MD001' then (dr_amt) else 0 end) as dr_cdnw,  
    sum(case account_id when 'MD001' then (balance) else 0 end) as bal_cdnw,  
    sum(case account_id when 'MD002' then (cr_amt) else 0 end) as cr_cdw,  
    sum(case account_id when 'MD002' then (dr_amt) else 0 end) as dr_cdw,  
    sum(case account_id when 'MD002' then (balance) else 0 end) as bal_cdw,  
    sum(case account_id when 'ML001' then (cr_amt) else 0 end) as cr_loan_ord,  
    sum(case account_id when 'ML001' then (dr_amt) else 0 end) as dr_loan_ord,  
    sum(case account_id when 'ML001' then (balance) else 0 end) as bal_loan_ord,  
    sum(case account_id when 'ML002' then (cr_amt) else 0 end) as cr_loan_emg,  
    sum(case account_id when 'ML002' then (dr_amt) else 0 end) as dr_loan_emg,  
    sum(case account_id when 'ML002' then (balance) else 0 end) as bal_loan_emg  
from TEMP_MEMBER_STATEMENT  
group by tran_date, tran_id  
order by tran_date, cast(tran_id as INT);

1 个答案:

答案 0 :(得分:4)

CAST function没有int目标。它可以是SIGNEDUNSIGNED,例如

ORDER BY ..., CAST(tran_id AS SIGNED)