日期:2014-05-18  浏览次数:20601 次

我想把这些记录显示出来的SQL语句怎么写啊?
是这样的,为了让大家更方便理解,我陈述如下:
现在auction表里的数据结构是这样的:
id       keyword       Currentprice
---------------------------
1           塑料               1300
2           塑料               1000
3           橡胶               300
4           钢铁               1200
5           钢铁               3000
6           油墨               1200

我想统计出不相同的keyword且出价值CurrentPrice最高的记录:
如我想得到如下结果:
id       keyword         Currentprice
1         塑料                   1300
3         橡胶                   300
5         钢铁                   3000
6         油墨                   1200

------解决方案--------------------
select a.* from auction a,
(select keyword , max(Currentprice) Currentprice from auction group by keyword) b
where a.keyword = b.keywore and a.currentprice = b.currentprice
------解决方案--------------------
select *from auction a where not exists(select 1 from auction b where a.keyword=b.keyword and a.Currentprice <b.Currentprice)