Order Oracle query by SUM without selecting the SUM

前端 未结 1 451
难免孤独
难免孤独 2021-01-23 22:14

I have a table somewhat like the following one:

 lot   |  defect  |  quantity
-------+----------+-----------
 lot1  |  c       |  7
 lot1  |  c       |  2
 lot3          


        
相关标签:
1条回答
  • 2021-01-23 22:37

    Your question seems to be about ordering the results. The solution is to use window functions in ORDER BY:

    SELECT lot, defect, SUM(quantity)
    FROM table
    GROUP BY lot, defect
    ORDER BY SUM(SUM(quantity)) OVER (PARTITION BY lot) DESC,
             lot, SUM(quantity) DESC, defect;
    
    0 讨论(0)
提交回复
热议问题