我有两个表,customers
和purchases
。 Purchases
具有total_price
列和涉及customers.cid
的外键cid
。我需要选择购买成本最高的客户(来)。SQL查询找到最大价格购买的名称?
我想这
select
cname
from
customers c
where exists
(select pid
from purchases p
where total_price in (select max(total_price)
from purchases p
where max(total_price) = total_price
and p.cid = c.cid))
我得到的错误,组的功能在这里不允许使用 - >
where max(total_price) = total_price
请帮我
哪个RDBMS是这个呢?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –