如何在SQL中排除第一条记录以外的记录

时间:2011-11-10 00:20:39

标签: sql

Current product  TempAnn      SrNo
-----------------------------------
Current Product  0.00         1
Match            20.96        2
Match            26.96        3
Current Product  0.00         1
Match            4.76         3
Match            5.76         2
Current Product  0.00         1
Match            32.40        3
Match            35.40        2
Current Product  0.00         1
Match            20.96        2
Match            2.96         3
Current Product  0.00         1
Match            29.76        2
Match            30.68        4
Match            24.04        3
Current Product  0.00         1
Match            16.92        3
Match            13.56        4
Match            22.64        2

需要对每个当前产品进行排序SrNo <> 1。例如,除了SrNo 1,2和3之外的第一个当前产品应该一起排序,使得它首先显示26.96然后显示20.96。

2 个答案:

答案 0 :(得分:2)

SELECT * FROM table ORDER BY SrNO=1 ASC, TempAnn DESC

答案 1 :(得分:0)

不确定是否可能,你绝对需要另一个专栏:

Current product  TempAnn      SrNo    tempCol
---------------------------------------------
Current Product  0.00         1         1
Match            20.96        2         1
Match            26.96        3         1
Current Product  0.00         1         2
Match            4.76         3         2
Match            5.76         2         2
Current Product  0.00         1         3
Match            32.40        3         3
Match            35.40        2         3
Current Product  0.00         1         4
Match            20.96        2         4
Match            2.96         3         4
Current Product  0.00         1         5
Match            29.76        2         5
Match            30.68        4         5
Match            24.04        3         5
Current Product  0.00         1         6
Match            16.92        3         6
Match            13.56        4         6
Match            22.64        2         6

所以你使用了正确的订单

SELECT *
From table
ORDER tempCol, TempAnn

编辑:

 SELECT *
    From table
    ORDER tempCol, SrNo = 1,  TempAnn Desc