MYSQL Sakila数据库 - 查找尚未租借电影的客户列表

时间:2017-03-12 05:48:07

标签: mysql sql

我在大学课程中第一次学习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;

然而,我一直收到错误"无效使用群组功能"而我似乎无法弄明白为什么。有人可以帮助我吗?

1 个答案:

答案 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
相关问题