Suppose there are 10 entries in one of the fields in which, 5 entries have a value of 1, and 5 entries have a value of 2. How can you sort them so that these entries go in turn, 1, 2, 1, 2 ..., A if some of the values ​​run out, that is, there will be records with only one of these values, so that they would just go in order. Thanks in advance.

    1 answer 1

    SELECT subquery.[fieldset] FROM (SELECT table.[fieldset] , ROW_NUMBER() OVER (PARTITION BY table.data_field ORDER BY table.some_unique_field) rn FROM table ) subquery ORDER BY subquery.rn ASC, subquery.data_field ASC