我有这段代码:
select inventory.store_id as store_id,
film.title as Titel_Film,
count(film.film_id) as Anz_ausleihbar
from film
join inventory on film.film_id = inventory.film_id
join (select rental.inventory_id, rental.return_date
from rental
group by rental.inventory_id) as rental2
on rental2.inventory_id = inventory.inventory_id
where film.title like '%B'
and inventory.store_id = 1
group by film.film_id
order by inventory.store_id asc, film.title desc
我收到错误错误:ORA-00905:缺少关键字。
谢谢你的帮助!
答案 0 :(得分:0)
将您的GROUP BY
更改为
GROUP BY store_id, Titel_Film
使用分组依据时,您需要指定"组字段"对于未汇总或汇总的所有字段。
答案 1 :(得分:0)
in
快,如果不需要返回数据,则比连接速度快。这也删除了表别名上的as
语句。
SELECT I.store_id as store_id
, f.title as Titel_Film
, count(f.film_id) as Anz_ausleihbar
FROM film
INNER JOIN inventory I
ON f.film_id = I.film_id
WHERE f.title like '%B'
AND i.store_id = 1
AND exists (SELECT *
FROM rental r2
WHERE r2.inventory_ID = i.inventory_ID)
GROUP BY I.store_id
, film.title
ORDER BY i.store_id asc, f.title desc