我有表格列
id doctor_name charges_cash charges_cashless
1 1 300 600
2 2 200 400
现在我正在尝试运行此查询:
SELECT ipd.patient_name, r.room_name, doctor.doctor_name,
CASE p.tpa_name
WHEN NULL
THEN i.charges_cash
ELSE i.charges_cashless
END AS 'charges'
FROM `daily_ward_entry` d, ipd_charges i, ipd_patient_entry ipd, room_charges r,
patient_detail p, doctor
WHERE d.doctor_visit_name = i.doctor
AND r.id = d.room_name
AND d.patient_name = ipd.id
AND d.doctor_visit_name = doctor.id
我收费的结果为400,而p.tpa_name为null,我预计为200, 我没有任何线索,我在这里做错了什么?
结果集就像这样
patient_name room_name doctor_name charges
Sapna Agrawal MG-1 Dr. Dungri 400
感谢。
答案 0 :(得分:2)
与IS
NULL
运算符
CASE WHEN p.tpa_name IS NULL
THEN i.charges_cash
ELSE i.charges_cashless
END AS 'charges'