六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 47|回复: 0

SQL over case 等语法学习

[复制链接]

升级  8.67%

17

主题

17

主题

17

主题

秀才

Rank: 2

积分
63
 楼主| 发表于 2013-1-27 04:42:21 | 显示全部楼层 |阅读模式
引子:一条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函数来分组处理数据(备忘)
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表