I have a table as this example:
CREATE TABLE customerEvent(
customerID int NOT NULL,
eventID int NOT NULL
)
customerID may appear in many records. I use the following query to identify most frequent customerID:
SELECT
customerID,eventID
,row_number() OVER(PARTITION BY customerID ORDER BY eventID) as frequency
FROM customerEvent
ORDER BY frequency DESC
With this I see those most frequent customerID. But they appear only once on the top of the list. Example:
customerID eventID frequency
7 3 5
15 9 4
7 1 4
9 4 3
7 10 3
15 2 3
I need all records of the most frequent customerID to appear on the top, example:
customerID eventID frequency
7 3 5
7 1 4
7 10 3
15 9 4
15 2 3
9 4 3
Any idea how I can build a query that does that?