T-SQL 统计最好的

来源:百度知道 编辑:UC知道 时间:2024/05/28 17:55:13
通过T-SQL语句统计销售最好商品的编号
通过T-SQL语句增加数量
当日销售表
商品编号用sno表示
商品名称用sname表示
商品价格用price表示
商品个数用piece表示
日期用time表示

商品编号(sno) 商品名称(sname) 商品价格(price) 商品个数(piece) 日期(date)
01 cake 1.8 5 07/5/16
02 Cola 2.0 2 07/5/16

这个语句可能会好一些。

select top 1 sno,sum(piece) as total_qty from 当日销售表 group by sno order by total_qty desc

declare @s int
select @s=max(piece) from newTable
select sno from newTable where @s=piece
我试过了,正确