Skip to content
Advertisement

How to COUNT duplicate rows?

I want to be able to create a histogram out of a tuple containing two integers values.

Here it is the query:

For this input:

Would be:

How can I create a histogram of those values?
In other words, how can I count how many times a row has a duplicate?

Advertisement

Answer

The question leaves room for interpretation. This test case shows 2 nested steps:

How many duplicates per value?

Result:

Read: ad_id 62 exists 1x, ad_id 288 exists 4x, …

How to count how many times rows have duplicates?

Result:

Read: 8 occurrences of “ad_id is unique”, 7 occurrences of “2 rows with same ad_id“, …

db<>fiddle here

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