joraboy328 发表于 2008-10-17 16:52

求条SQL语句

原数据:
id corp goodsnums
-- ---- -------- ----
1 ACOMPUTER 2000
2 ACOMPUTER 3000
3 ACD      20
4 ACD      25
5 ACD      22
6 BCOMPUTER 2500
7 BCOMPUTER 3000

返回每个公司每种产品卖出的最多量,SQL如下?
select a.corp,a.goods,a.nums from test a
where a.id in
(select top 1 b.id from test b where b.corp=a.corp and b.goods=a.goods
order by b.nums)
group by a.corp,a.goods,a.nums

Sybase 报错说TOP有问题,不支持吗?能不能给个SQL达到我的目的,谢谢

但单独用select top 10 * from table是可以的,奇怪!

chenfeng825 发表于 2008-10-20 08:54

1.having
2.top n 不能用在起源表
页: [1]
查看完整版本: 求条SQL语句