Sql Order by on multiple column

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

I\'ve the below result

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


        
4条回答
  •  有刺的猬
    2021-02-13 06:27

    This will do it ...

    ORDER BY MAX(INCIDENTDATE) OVER (PARTITION BY VENDORNAME) DESC, INCIDENTDATE DESC
    

    ... but I'm not sure if the analytic function is allowed in the ORDER BY. If it isn't, calculate it in a subquery and order by in the main query ...

    select ...
    from   (
      select Max(incidentdate) over (partition by vendorname) max_incidentdate_by_vendor,
             ...)
    order by max_incidentdate_by_vender desc, incidentdate desc
    

提交回复
热议问题