我在大学课程中第一次学习SQL,并且我们正在使用流行的Sakila数据库。我一直坚持这个问题 - 查找尚未租借电影的客户列表。到目前为止,我的思维过程是这样的:
#List of customers who have not rented a movie yet
SELECT
concat(c.first_name, " ", c.last_name), count(r.rental_id) as "Number of Rentals"
FROM
customer c, rental r
WHERE
c.customer_id = r.customer_id
AND count(r.rental_id) is NULL
GROUP BY
c.customer_id;
然而,我一直收到错误"无效使用群组功能"而我似乎无法弄明白为什么。有人可以帮助我吗?
答案 0 :(得分:0)
尝试将WHERE
语句更改为Having
语句,如下所示:
SELECT
concat(c.first_name, " ", c.last_name), count(r.rental_id) as "Number of Rentals"
FROM
customer c, rental r
WHERE
c.customer_id = r.customer_id
GROUP BY
c.customer_id
HAVING count(r.rental_id) is NULL