This table / data:
WITH T(col1, col2) AS(
SELECT 1, 'A' FROM DUAL
UNION ALL
SELECT 2, 'B' FROM DUAL
UNION ALL
SELECT 3, 'B' FROM DUAL
UNION ALL
SELECT 4, 'B' FROM DUAL
UNION ALL
SELECT 5, 'A' FROM DUAL
UNION ALL
SELECT 6, 'B' FROM DUAL
UNION ALL
SELECT 7, 'B' FROM DUAL
UNION ALL
SELECT 8, 'A' FROM DUAL
)
I need to get the col2number of repeated queue queues, I mean, how many times the same value was repeated in col2when the rows are orderedcol1
The result should be:
col1 | col2 | queue_count
-------------------------
1 |A |1
2 |B |3
3 |B |3
4 |B |3
5 |A |1
6 |B |2
7 |B |2
8 |A |1
I tried some analytic functions, but did not achieve the desired result.
Can this be done in pure SQL? without using pl / sql (without loops and every line of step-by-step control, etc.)
source
share