我有3个表:产品,类别和product_category (哪些产品在每个类别中)。
我想要每个类别中最贵的3种产品。
我有一个基本的关系:
select c.name
, p.id
, p.price
from category c
left
join product_category pc
on pc.category_id = category.id
left
join product p
on pc.product_id = p.id
但现在我只想买每个类别中最贵的3个。
在这种情况下,我们可以使用任意数量的连接表,并且可
我正在整理一份清单,上面的商品从最贵的到最便宜的。我只能成功地识别出最贵的那台,而我不知道如何识别middel one或最便宜的那台。如果有人能帮助我,我将不胜感激。这是我的代码:
def sort_prices(list_of_tuples):
i = 0
count = 0
the_new_list = [] # the final list with the products
for prices in list_of_tuples:
price = float(prices[1])
count = 0
fo
假设我有以下模式:
BUDGETS
-------
DEPT (string)
ITEM (string)
BUDGET (integer)
我想要找到最便宜的产品,这是最昂贵的部门,没有任何子查询。这有可能吗?
我有:
with max_per_dept as
(select dept, max(budget) as budget
from budgets
group by dept)
select min(budget) from max_per_dept;