SELECT title FROM film WHERE film_id in ( SELECT count(inventory.inventory_id) as counter FROM inventory WHERE film_id = film.film_id and counter = 8 )
我正在尝试显示库存中正好有8个副本的所有电影片名,但我似乎找不到使用子查询的正确方法。
ibps3vxo1#
您必须在表inventory中按film_id分组,并为HAVING子句中可用的8个副本设置条件:
inventory
film_id
HAVING
SELECT title FROM film WHERE film_id in ( SELECT film_id FROM inventory GROUP BY film_id HAVING COUNT(*) = 8 );
rt4zxlrg2#
这应该可以做到:
SELECT title FROM film WHERE film_id in (SELECT FILM_ID FROM (SELECT FILM_ID, COUNT(*) AS COUNTER FROM INVENTORY GROUP BY FILM_ID) WHERE COUNTER = 8)
2条答案
按热度按时间ibps3vxo1#
您必须在表
inventory
中按film_id
分组,并为HAVING
子句中可用的8个副本设置条件:rt4zxlrg2#
这应该可以做到: