表内容:
FItemID FInterID FPrice
19387 1574 17.0940000000
19387 25124 16.6666670000
19387 27992 16.2393160000
19388 28324 16.6666670000
19387 29632 16.6666670000
19387 29632 16.6666670000
19389 31074 17.0940170000
19387 31862 16.6666670000
希望等到的结果:
FItemID FInterID FPrice
19387 1574 17.0940000000
19387 25124 16.6666670000
19388 28324 16.6666670000
19389 31074 17.0940170000
即根据fitemid 去除Fprice重复的值
------解决思路----------------------
逻辑:1、根据主键,或相同的数据分组,2、取其一
select *
from (
select FItemID,FInterID,FPrice,
row_number() over(partition by FItemID,FInterID order by FItemID) as SN
) as t
where t.SN=1
------解决思路----------------------
--如果只有这三列,直接这样即可
SELECT FItemID,MIN(FInterID)FInterID,FPrice
FROM TB
GROUP BY FItemID,FPrice
--如果有其它列,表连接也挺快
SELECT T1.* FROM TB T1
LEFT JOIN TB T2 ON T1.FItemID=T2.FItemID
AND T1.FPrice=T2.FPrice AND T1.FInterID<T2.FInterID
WHERE T2.FItemID IS NULL