提问者:小点点

编写一个查询来查找那些至少租了一部电影并且属于阿灵顿市的客户的全名


我收到一个错误,说输出与给定的问题不匹配

Sakila数据库:https://dev.mysql.com/doc/Sakila/en/sakila-structure.html

下面是我的代码

with temp as (
select concat(b.first_name, ' ',b.last_name) as name,
count(a.rental_id >= 1) as rental_count
from rental a
inner join customer b ON   (a.customer_id=b.customer_id)
inner join address c ON    (b.address_id=c.address_id)
inner join city d ON       (c.city_id=d.city_id)
where d.city like "Arlington"
group by name
order by rental_count
)
select name from temp

预期结果是

full names of those customers who have rented at least one movie and belong to the city Arlington.

请你告诉我是什么错误,还是有别的办法?


共1个答案

匿名用户

可以使用having子句,请尝试以下操作

select 
    concat(b.first_name, ' ',b.last_name) as name
from rental a
inner join customer b 
on a.customer_id = b.customer_id
inner join address c    
on b.address_id = c.address_id
inner join city d       
on c.city_id = d.city_id
where d.city = 'Arlington'
group by 
    concat(b.first_name, ' ',b.last_name)
having count(a.rental_id) >= 1