首页 新闻 会员 周边 捐助

请教SQL问题。查询最小值的ID

0
悬赏园豆:60 [已解决问题] 解决于 2013-12-13 09:48

ID      NO              Price
239 TRA13120001 490.00
240 TRA13120001 100.00
241 TRA13120001 490.00
242 TRA13120001 480.00
243 TRA13120009 490.00
244 TRA13120009 490.00
245 TRA13120009 430.00
246 TRA13120009 490.00
247 TRA13120002 450.00
248 TRA13120002 490.00
249 TRA13120002 490.00

上面是数据库数据,求教各位如何写sql语句,去除NO重复,查询出最小Price 的ID 不要使用Order By 我试了好多,都不行谢谢各位了!

得到结果
240
245
247

平~安~喜~乐的主页 平~安~喜~乐 | 初学一级 | 园豆:86
提问于:2013-12-12 20:55
< >
分享
最佳答案
0

SELECT ID FROM wolfe WHERE price IN (SELECT min(price) FROM wolfe GROUP BY acc);

收获园豆:30
Wolfe Yu | 菜鸟二级 |园豆:434 | 2013-12-13 09:14
其他回答(2)
0

select ID from Order where Price=(select min(Price) from Order) 

Order是你的表名,改一下

收获园豆:10
zjruan | 园豆:219 (菜鸟二级) | 2013-12-12 22:20
0

SELECT * FROM(
SELECT p.ID,p.NO,p.Price,ROW_NUMBER() OVER (PARTITION BY p.NO ORDER BY p.Price) RN
FROM
(
select '239' as ID ,'TRA13120001' as NO,'490.00' as Price union all
select '240' as ID ,'TRA13120001' as NO,'100.00' as Price union all
select '241' as ID ,'TRA13120001' as NO,'490.00' as Price union all
select '242' as ID ,'TRA13120001' as NO,'480.00' as Price union all
select '243' as ID ,'TRA13120009' as NO,'490.00' as Price union all
select '244' as ID ,'TRA13120009' as NO,'490.00' as Price union all
select '245' as ID ,'TRA13120009' as NO,'430.00' as Price union all
select '246' as ID ,'TRA13120009' as NO,'490.00' as Price union all
select '247' as ID ,'TRA13120002' as NO,'450.00' as Price union all
select '248' as ID ,'TRA13120002' as NO,'490.00' as Price union all
select '249' as ID ,'TRA13120002' as NO,'490.00' as Price) AS p ) AS t WHERE t.RN=1 ORDER BY t.ID

 

收获园豆:20
冰魄少年 | 园豆:224 (菜鸟二级) | 2013-12-13 07:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册