I want to be able to create a histogram out of a tuple containing two integers values.
Here it is the query:
SELECT temp.ad_id, temp.distance as hits FROM (
'UNION ALL .join(cupound_query)' # python
) as temp GROUP BY temp.ad_id,temp.distance
For this input:
(51, 5)
(51, 0)
(51, 3)
(51, 0)
(88, 2)
(88, 2)
(88, 2)
(84, 1)
(81, 9)
Would be:
(88,2) : 3
(51,0) : 2
(51,3) : 1
(51,5) : 1
(84,1) : 1
(81,9) : 1
How can I create a histogram of those values?
In other words, how can I count how many times a row has a duplicate?
The question leaves room for interpretation. This test case shows 2 nested steps:
How many duplicates per value?
Result:
Read:
ad_id 62exists 1x,ad_id 288exists 4x, …How to count how many times rows have duplicates?
Result:
Read: 8 occurrences of "
ad_idis unique", 7 occurrences of "2 rows with samead_id", …db<>fiddle here