Sql Order by on multiple column

后端 未结 4 1248
小鲜肉
小鲜肉 2021-02-13 06:10

I\'ve the below result

VendorName | IncidentID | IncidentStatus | IncidentDate
-------------------------------------------------------
XYZ        | 100        |         


        
4条回答
  •  眼角桃花
    2021-02-13 06:16

    Use analytic functions:

    SELECT *
    FROM(
        SELECT 
            VendorName, 
            IncidentID, 
            IncidentStatus, 
            IncidentDate, 
            MAX(IncidentDate) OVER (PARTITION BY VendorName) maxDate
        FROM yourTable
    ) t
    ORDER BY t.maxDate DESC, t.VendorName ASC, t.IncidentDate DESC
    

    Refer to: http://docs.oracle.com/javadb/10.8.2.2/ref/rrefsqlj13658.html http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions003.htm http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm

提交回复
热议问题