以下是我寫的測試跟範例
使用ORDER BY CASE WHEN達到ASC跟DESC
--測試資料
create table #Tem_Table ([Date] Date,group_num int );
with Tem_Table as (
select '2018-03-01' [Date],1 group_num union all
select '2018-03-04' [Date],1 group_num union all
select '2018-03-02' [Date],1 group_num union all
select '2018-03-02' [Date],3 group_num union all
select '2018-03-05' [Date],3 group_num union all
select '2018-03-03' [Date],3 group_num
)
insert into #Tem_Table select * from Tem_Table;
select * from #Tem_Table;
select * from #Tem_Table
order by
case when group_num=1 then [DATE] end DESC, --group_num=1的,組內時間DESC
case when group_num=3 then [DATE] end ASC --group_num=3的,組內時間ASC。