РЕДАКТИРОВАТЬ: Вся вещь заменена, так как недавнее редактирование вопроса показывает, что GROUP BY не требуется ...
Без каких-либо измененийдля «элегантности» ...
SELECT
rsu.last_name + ', ' + rsu.first_name + COALESCE (' ' + rsu.middle_name + '.', '') as student_name,
rsu.day_id
FROM
roster_school_unattended AS [rsu]
ORDER BY
rsu.last_name + ', ' + rsu.first_name + COALESCE (' ' + rsu.middle_name + '.', ''),
rsu.day_id
Возможные изменения для «элегантности» ...
WITH formatted_rsu AS
(
SELECT rsu.last_name + ', ' + rsu.first_name + COALESCE (' ' + rsu.middle_name + '.', '') as student_name, rsu.day_id
FROM roster_school_unattended AS [rsu]
)
SELECT student_name, day_id
FROM formatted_rus
ORDER BY student_name, day_id
Другое возможное использование APPLY ...
SELECT formatted_rsu.student_name, rsu.day_id
FROM roster_school_unattended AS [rsu]
CROSS APPLY (SELECT rsu.last_name + ', ' + rsu.first_name + COALESCE (' ' + rsu.middle_name + '.', '') as student_name) AS [formatted_rsu]
ORDER BY formatted_rsu.student_name, rsu.day_id