Skip to content
Advertisement

Using PostgreSQL Case When with Partition

I am trying to use Case when with partition to create a new row and mark whether its duplicated or not

My desired output is shown below

enter image description here

The query I am using

I cant find the error here. It seemed to work in SQL Server before

Advertisement

Answer

I think > 1 should be out of (PARTITIONBY x, y) like this:

Comprasion operator itself results on boolean, so you don’t need case:

But this will result, marking duplicate only the rows after the first row, meaning first Carlo Thomas will not be duplicate.

So for the desired result, you need this:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement