sql - subquery must return only one column , how can i fix it
问题描述
How many times has any customer whose first name starts with “A” rented movies in which “JULIA MCQUEEN” (first name Julia) acted? Your solution must use joins and your output should be a single number.
SELECT count(r.rental_id)
FROM rental r
JOIN customer c on r.customer_id = c.customer_id
JOIN store s on c.store_id = s.store_id
JOIN inventory i on s.store_id = i.store_id
JOIN film_actor fa on i.film_id = fa.film_id
JOIN actor a on fa.actor_id = a.actor_id
WHERE a.actor_id = 21 and c.first_name = (select * FROM customer where first_name like 'A%');
how can i fix it
解决方案
- 而不是
c.first_name = (select * ...) use
c.first_name = like 'A%'` - 也用
GROUP BY c.customer_id
。 - 根据问题,您应该具有演员名称为的条件
a.first_name = 'Julia'
。
您的完整查询将如下所示。
SELECT c.customer_id, count(r.rental_id) rented_count
FROM rental r
JOIN customer c on r.customer_id = c.customer_id
JOIN store s on c.store_id = s.store_id
JOIN inventory i on s.store_id = i.store_id
JOIN film_actor fa on i.film_id = fa.film_id
JOIN actor a on fa.actor_id = a.actor_id
WHERE a.first_name = 'Julia' and c.first_name like 'A%'
GROUP BY c.customer_id
推荐阅读
- python - tensorflow 导入错误:在 Python 2.7 中没有名为 tensorflowin Jupyter 的模块
- swift - 如何在悬停 NSTextView 上更改光标?斯威夫特 4,Xcode 9.4
- mysql - 无法打开引用的表
- xml - 使用 XSLT 1.0 更改 XML 输出结构
- javascript - 以英寸为单位的数量转换为英尺、厘米或码 Javascript
- php - 如何用js和每个项目的输出值制作一个可选择的项目菜单
- javascript - 如何在 Firebase Web 中创建两个用户组
- python - Python字典和设置内存分配
- android - 持久底片
- java - While循环折旧(帮助)