Quantcast
Channel: Questions in topic: "cte"
Viewing all articles
Browse latest Browse all 75

Removing duplicate entries query not working

$
0
0

table.jpg

In the attached table, I'm trying to identify and delete the duplicate records which have 0 rates.

E.G. line #2 and line #5. I want to keep the records with rates as 0 that do not have duplicate entries.

I'm using the query below, and it's not giving me the results I need. It's assigning row number=1 for entries where rates are 0, and then row number=2 for the valid record.

I think I may need an additional subquery or something?

WITH CTE AS( SELECT tblname.*,

RN = ROW_NUMBER()OVER(PARTITION BY region, state, month

ORDER BY rate, rate2, rate3 DESC) FROM tablename )

select * FROM CTE WHERE RN = 1


Viewing all articles
Browse latest Browse all 75

Trending Articles