考虑下面的mysql语句:

SELECT costs.cost AS package, payments.cost AS labs, patients.fname, patients.lname, patients.sname, visit.id AS visitid, patients.id, pharm_payments.cost AS pharm_costs ,costs.cost+payments.cost+pharm_payments.cost AS total_cost ,
CASE pharm_payments.cost WHEN pharm_payments.visitid=visit.id THEN pharm_payments.cost
WHEN pharm_payments.visitid != visit.id THEN 0
CASE costs.cost WHEN cost.visitid=visit.id THEN costs.cost
WHEN costs.visitid != visit.id THEN 0
FROM costs
LEFT JOIN visit ON costs.visitid = visit.id
LEFT JOIN patients ON visit.patientid = patients.id
LEFT JOIN pharm_payments ON pharm_payments.visitid = visit.id
LEFT JOIN payments ON payments.visitid = visit.id
WHERE costs.paid =  'not paid'
AND visit.VisitDate >= CURDATE( )
LIMIT 0 , 30


查询的预期结果应为访问ID不同的地方,应返回零值。我不断收到以下错误:

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 'CASE costs.cost WHEN cost.visitid=visit.id THEN costs.cost WHEN costs.visitid !=' at line 4


我该如何解决这个错误?

最佳答案

我对SQL语句中case的使用不熟悉,但是shouldn't you put an END after?

关于php - 带有否定的MYSQL中的多种情况陈述,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19632260/

10-10 14:47