在where-section中使用max()的替代方法?

时间:2018-09-14 10:48:14

标签: sql postgresql greatest-n-per-group

我对SQL还是很陌生,我只想显示一本最昂贵的书。我的第一个想法是从max(books.purchase_price)中删除select并将max(books.purchase_price) = books.purchase_price添加到where部分。但这给了我一个错误信息。

select categories.category, max(books.purchase_price) as price
from books, categories
where categories.category_id = books.category_id
group by categories.category
order by pris desc
limit 1

只有两个表:books,其中包含标题,价格和category_id条目;和categories具有category_id和不同的类别(名称)。

0 个答案:

没有答案