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
SELECT ID FROM wolfe WHERE price IN (SELECT min(price) FROM wolfe GROUP BY acc);
select ID from Order where Price=(select min(Price) from Order)
Order是你的表名,改一下
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