0
選擇執行後,我收到了錯誤「未知列‘點’在‘where子句’刪除行時,子查詢返回null
如何從包含空外部查詢中刪除行記錄從子查詢返回?(我需要使用子查詢,因爲我有需要運行到返回結果子查詢的另一幫我後)
SELECT
s.student_name_first,
s.student_name_last,
(
SELECT sum(i.points)
FROM incidents i
WHERE i.student = s.id
) AS points
FROM students s
WHERE points IS NOT NULL
GROUP BY s.id
我也曾嘗試,結果相同
SELECT
s.student_name_first,
s.student_name_last,
(
SELECT sum(i.points) AS points
FROM incidents i
WHERE i.student = s.id AND points IS NOT NULL
) AS p
FROM students s
GROUP BY s.id
在此先感謝
解決方案:
我一直在尋找的是HAVING
SELECT
s.student_name_first,
s.student_name_last,
(
SELECT COALESCE(sum(i.incident_points),0)
FROM incidents i
WHERE i.student = s.id
) as points
FROM students s
GROUP BY s.id
HAVING points > 0
Reword「防止在子查詢上返回空記錄」部分,因爲刪除外查詢中包含空值的行是不相同的,因爲防止子查詢返回空值。 –
重寫,希望可以幫助 –
好的,謝謝,我將我的答案與此表單無關。巴馬爾的就足夠了。 –