我收到一个错误,说输出与给定的问题不匹配
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.
请你告诉我是什么错误,还是有别的办法?
可以使用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