Order by x then order by y column in SQL Server

后端 未结 4 1131
忘掉有多难
忘掉有多难 2021-01-19 05:11

Consider a table like

   debit    credit  code
-----------------------------
    0       10      5
    5       0       3
    0       11      2
    0       15         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-19 06:16

    Use this select to help you:

    SELECT debit, code, credit  
    FROM table a
    WHERE debit > 0
    or debit = 0
    order by debit  code, credit desc
    

    or

    SELECT debit, code, credit  
    FROM table a
    WHERE debit > 0
    or debit = 0
    group by debit, code, credit
    order by debit  code, credit desc
    

提交回复
热议问题