我试图找到一种方法来运行它:
SELECT
s.system_number,
s.total_points,
p.licensed_points,
SUM(p.licensed_points) - SUM(s.total_points) AS difference_points
FROM
server AS s
LEFT JOIN
practice AS p ON p.system_number = s.system_number
WHERE
difference_points < 0
我的目标是仅选择差异点<0的对象
有人知道该怎么做吗?
谢谢
答案 0 :(得分:1)
Sum()
的情况下使用聚合函数Group By
毫无意义。您将需要在Group By
上进行s.system_number
。Having
子句来考虑difference_points
小于0的情况。请尝试以下操作:
SELECT
s.system_number,
SUM(s.total_points),
SUM(p.licensed_points),
SUM(p.licensed_points) - SUM(s.total_points) AS difference_points
FROM
server AS s
LEFT JOIN
practice AS p ON p.system_number = s.system_number
GROUP BY
s.system_number
HAVING
difference_points < 0