Sql aGohil此查询生成的行的顺序与您的相同。如果要对CreatedDt进行降序排序,请在ORDER BY CreatedDt@DevendraGohil之后插入desc:我更新了答案,以说明如何为主要排序标准指定降序。(对不起,你的帖子中没有提到这一点。)
Sql aGohil此查询生成的行的顺序与您的相同。如果要对CreatedDt进行降序排序,请在ORDER BY CreatedDt@DevendraGohil之后插入desc:我更新了答案,以说明如何为主要排序标准指定降序。(对不起,你的帖子中没有提到这一点。),sql,sql-server,sql-server-2008,plsql,Sql,Sql Server,Sql Server 2008,Plsql,aGohil此查询生成的行的顺序与您的相同。如果要对CreatedDt进行降序排序,请在ORDER BY CreatedDt@DevendraGohil之后插入desc:我更新了答案,以说明如何为主要排序标准指定降序。(对不起,你的帖子中没有提到这一点。) SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblA union SELECT CreatedDt as 'Date/Time' , null AS [Alert
aGohil此查询生成的行的顺序与您的相同。如果要对CreatedDt进行降序排序,请在
ORDER BY CreatedDt
@DevendraGohil之后插入desc
:我更新了答案,以说明如何为主要排序标准指定降序。(对不起,你的帖子中没有提到这一点。)
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblA
union
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblB
union
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblC
union
SELECT CreatedDt as 'Date/Time' , Alert_Type FROM TblD
ORDER BY CreatedDt, ISNULL (Alert_Type,'aa') DESC
ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.
ORDER BY CASE WHEN column_name IS NULL
THEN 1
ELSE 0
END ASC --, other sorts
-- in these case NULL columns should be on the bottom part
select * from (
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblA
union
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblB
union
SELECT CreatedDt as 'Date/Time' , null AS [Alert_Type] FROM TblC
union
SELECT CreatedDt as 'Date/Time' , Alert_Type FROM TblD)a
order by CreatedDt desc,
case when Alert_Type is null then 0 else 1 end
SELECT CreatedDt as 'Date/Time' , 'aa' AS [Alert_Type] FROM TblA
union
SELECT CreatedDt as 'Date/Time' , 'aa' AS [Alert_Type] FROM TblB
union
SELECT CreatedDt as 'Date/Time' , 'aa' AS [Alert_Type] FROM TblC
union
SELECT CreatedDt as 'Date/Time' , Alert_Type FROM TblD
ORDER BY CreatedDt DESC, Alert_Type DESC