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

tpgth1q7  于 2021-08-09  发布在  Java
关注(0)|答案(2)|浏览(363)

我得到一个错误,说输出与给定的问题不匹配
sakila数据库: https://dev.mysql.com/doc/sakila/en/sakila-structure.html 下面是我的代码

  1. with temp as (
  2. select concat(b.first_name, ' ',b.last_name) as name,
  3. count(a.rental_id >= 1) as rental_count
  4. from rental a
  5. inner join customer b ON (a.customer_id=b.customer_id)
  6. inner join address c ON (b.address_id=c.address_id)
  7. inner join city d ON (c.city_id=d.city_id)
  8. where d.city like "Arlington"
  9. group by name
  10. order by rental_count
  11. )
  12. select name from temp

预期结果是

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

你能告诉我是什么错误吗?或者有别的办法吗?

drnojrws

drnojrws1#

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

  1. select
  2. concat(b.first_name, ' ',b.last_name) as name
  3. from rental a
  4. inner join customer b
  5. on a.customer_id = b.customer_id
  6. inner join address c
  7. on b.address_id = c.address_id
  8. inner join city d
  9. on c.city_id = d.city_id
  10. where d.city = 'Arlington'
  11. group by
  12. concat(b.first_name, ' ',b.last_name)
  13. having count(a.rental_id) >= 1
olqngx59

olqngx592#

  1. select concat(first_name," ", last_name) as Customer_name
  2. from rental
  3. inner join customer
  4. using (customer_id)
  5. inner join address
  6. using(address_id)
  7. inner join city
  8. using (city_id)
  9. where city = "Arlington"
  10. group by Customer_name
  11. having count(rental_id) > 0

相关问题