我有一个分配,我要运行以下选择查询: "只考虑缺少某些信息的学生,这个学生姓氏的第一个字母出现了8次?"
我到目前为止的查询是在下面,但它给出了一个错误,即语法错误在或附近" LEFT":
SELECT LEFT(last, 1)
FROM hogwarts_students
WHERE COUNT LEFT(last, 1) = 8
AND finish IS NULL;
答案 0 :(得分:2)
聚合函数在某些DBMS中需要GROUP BY子句。
SELECT LEFT(last, 1)
FROM hogwarts_students
WHERE finish IS NULL
GROUP BY LEFT(last, 1)
HAVING COUNT (*) = 8;