这里面ID为002和005的记录是重复的,在这里要把其中一条去掉,达到下面的效果:
--去掉重复的记录
select
ID,Code,ColorNum
from
(
SELECT
ROW_NUMBER() OVER(
PARTITION
BY
Code+ColorNum
ORDER
BY
Code+ColorNum
) rn,
ID,Code,ColorNum
FROM
TwoColumns
) a
where
a.rn=1
order
by
ID
SELECT
a.id,
a.name,
a.billno ,
a.billtype ,
a.msg,
a.create_time,
a.create_by
FROM
(SELECT
ROW_NUMBER() OVER(
PARTITION BY billno+billtype
ORDER BY billno+billtype
) rn,
ID,billno,billtype,msg,create_time,create_by,name
FROM ERP_KINGDEE_SYNC_ERR_LOG) a
WHERE
a.create_time BETWEEN '2019-10-1 00:00:00'
AND '2019-10-31 23:59:59'
AND a.msg LIKE '%单生产入库单,编码唯??%'
AND a.rn=1