我想写一段SQL,可以显示所有人里面花钱最多的那一位,并且把他的名字和...
发布网友
发布时间:2024-09-17 00:38
我来回答
共2个回答
热心网友
时间:2024-09-30 09:26
不知你用的是什么数据库?sqlserver与oracle语法分别如下,其它的就不知道了:)
SQL Server:
select top 1 *
from (
SELECt c.custID,sum(o.quantity*i.unitcost) as s
from items i, orders o, customers c
where i.itemID=o.itemID and c.custID=o.custID
group by c.custID
) order by s desc
Oracle:
select *
from (
select *
from (
SELECt c.custID,sum(o.quantity*i.unitcost) as s
from items i, orders o, customers c
where i.itemID=o.itemID and c.custID=o.custID
group by c.custID
) order by s desc )where rownum=1;
也可使用oracle的开窗函数来做
热心网友
时间:2024-09-30 09:29
不能能不结果I那你接哦就感觉不卖狗肉感慨吗美女覅