任务目标:显示客户的ID和姓氏,考试费用总计至少$ 300.00且不超过$ 900.00。
我尝试使用HAVING过滤掉它,但这不起作用。有什么建议吗?
SELECT
ISNULL(CASE WHEN SUM(ED.ex_fee) >=300 and SUM(ED.ex_fee) < 900 THEN CL.cl_id END,'') AS cl_id,
ISNULL(CASE WHEN SUM(ED.ex_fee) >=300 and SUM(ED.ex_fee) < 900 THEN CL.cl_name_last END,'') AS cl_name_last
FROM vt_clients as CL
INNER JOIN vt_animals AS AN ON AN.cl_id = CL.cl_id
INNER JOIN vt_exam_headers AS EH ON EH.an_id = AN.an_id
INNER JOIN vt_exam_details AS ED ON ED.ex_id = EH.ex_id
GROUP BY CL.cl_id, cl_name_last
HAVING CL.cl_id <> 0 and CL.cl_name_last <> ''
答案 0 :(得分:3)
试试这个
SELECT CL.cl_id, cl_name_last
FROM vt_clients as CL
INNER JOIN vt_animals AS AN ON AN.cl_id = CL.cl_id
INNER JOIN vt_exam_headers AS EH ON EH.an_id = AN.an_id
INNER JOIN vt_exam_details AS ED ON ED.ex_id = EH.ex_id
GROUP BY CL.cl_id, cl_name_last
HAVING SUM(ED.ex_fee) >=300 and SUM(ED.ex_fee) < 900