我有以下存储过程会产生语法错误:
SELECT
tbl_ReceiptMaster.receiptMasterId AS ID,
date_format(tbl_ReceiptMaster.date,'%d %m %y') AS Date,
tbl_AccountLedger.acccountLedgerName AS 'Ledger ',
tbl_ReceiptMaster.receiptMode AS 'Receipt Mode',
tbl_ReceiptMaster.description AS Description,
cast( tbl_ReceiptDetails.amount as decimal(18,2))as amount
FROM tbl_ReceiptMaster
INNER JOIN tbl_ReceiptDetails ON tbl_ReceiptMaster.receiptMasterId = tbl_ReceiptDetails.receiptMasterId
INNER JOIN tbl_AccountLedger ON tbl_ReceiptDetails.ledgerId = tbl_AccountLedger.ledgerId
order by cast (tbl_ReceiptMaster.receiptMasterId as decimal(10,2)) desc ;
这是错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'decimal(10,2)) desc' at line 11
如何解决此错误?
答案 0 :(得分:3)
您可以按顺序使用别名amount
而不是表达式cast( tbl_ReceiptDetails.amount as decimal(18,2))
,请尝试以下解决方案
SELECT tbl_ReceiptMaster.receiptMasterId AS ID,
date_format(tbl_ReceiptMaster.date,'%d %m %y') AS Date,
tbl_AccountLedger.acccountLedgerName AS 'Ledger ',
tbl_ReceiptMaster.receiptMode AS 'Receipt Mode',
tbl_ReceiptMaster.description AS Description,
cast( tbl_ReceiptDetails.amount as decimal(18,2))as amount
FROM tbl_ReceiptMaster
INNER JOIN tbl_ReceiptDetails ON tbl_ReceiptMaster.receiptMasterId = tbl_ReceiptDetails.receiptMasterId
INNER JOIN tbl_AccountLedger ON tbl_ReceiptDetails.ledgerId = tbl_AccountLedger.ledgerId
order by amount desc ;