Hi ruben00000,
You need to use ROW_NUMBER function for order by.
Refer below sample query.
SQL
CREATE TABLE #Temp(Customer_ID Varchar(MAX),Transaction_Date Varchar(MAX))
INSERT INTO #Temp VALUES(20,'1')
INSERT INTO #Temp VALUES(20,'2')
INSERT INTO #Temp VALUES(20,'3')
INSERT INTO #Temp VALUES(15,'1')
INSERT INTO #Temp VALUES(15,'2')
INSERT INTO #Temp VALUES(15,'3')
INSERT INTO #Temp VALUES(16,'1')
INSERT INTO #Temp VALUES(21,'31')
SELECT Customer_ID,Total_Penjualan
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY Customer_ID ASC) RowNo
,a.Customer_ID,
COUNT(a.Transaction_Date) Total_Penjualan
FROM #Temp a
GROUP BY a.Customer_ID
)t
ORDER BY Total_Penjualan DESC,RowNo
DROP TABLE #Temp
Output
Customer_ID |
Total Penjualan |
15 |
3 |
20 |
3 |
16 |
1 |
21 |
1 |