hydex 发表于 2013-1-27 04:42:21

SQL over case 等语法学习

引子:一条sql:
table:
NO        ID           THICK                WIDTH
----      -----         ----------            -----------
 1          a              100                    200
 2          b              110                    290
 3          e              90                      100
 4          f               190                    220
 5          h              290                    120
 6          c               220                    110
 7          d              100                    202
 8          i                280                   320
目的:移动指定的连续几行到指定行前,并且更新行号
  select (case
         when no < 4 then
          no
         when no >= 4 and no <= 5 then
          no + (8 - 5 - 1)
         when no > 5 and no < 8 then
          no - (5 - 4 + 1)
         when no >= 8 then
          no
       end) no,
       id,
       thick,
       width
  from (select id, thick, width, row_number() over(order by no) no from test) a
 order by no;
 
其中有些语法是值得看一下的, case when then end           over()的使用 
 
这里只是备忘,具体的东西,再仔细看
 
 
附:1.group by结合sum等Oracle函数来分组处理数据(备忘)
页: [1]
查看完整版本: SQL over case 等语法学习