说我有以下模式:
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;
答案 0 :(得分:1)
如果我的理解正确,那么您希望该产品是任何部门中最便宜的“最昂贵”产品。
一种方法使用order by
:
select b.*
from budgets b
order by max(budget) over (partition by dept) asc,
dept,
budget desc
fetch first 1 row only;