I have a data like this. I want to sort this data with a different ProviderId for each row.
Table1
ProviderId Tags
1 home
2 phone
3 notebook
3 phone
2 ...
2 ...
1 ...
1 ...
Below I am attaching an example of what I want to do.
Table1
ProviderId Tags
1 ...
2 ...
3 ...
1 ...
2 ...
3 ...
CodePudding user response:
Try:
WITH cte AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY ProviderId ORDER BY ProviderId) as row_num
FROM Table1)
SELECT ProviderId,Tags
FROM cte
ORDER BY row_num;