我有一个表如下:
区域 类别 金额
河北 11111111 400
河北 13000003 600
河北 22222222 10000
上海 11000222 700
上海 20000345 300
上海 22222222 800想实现以下效果
区域 类别 金额
河北 11111111 400
河北 22222222 10000
上海 11000222 700
上海 22222222 800上表有两个大类别,为1和2,两类
需要对于每个区域,类别为相同字符的金额显示,如果不存在字符相同的类别,将单独显示。
这种怎么实现啊?
区域 类别 金额
河北 11111111 400
河北 13000003 600
河北 22222222 10000
上海 11000222 700
上海 20000345 300
上海 22222222 800想实现以下效果
区域 类别 金额
河北 11111111 400
河北 22222222 10000
上海 11000222 700
上海 22222222 800上表有两个大类别,为1和2,两类
需要对于每个区域,类别为相同字符的金额显示,如果不存在字符相同的类别,将单独显示。
这种怎么实现啊?
SQL> with tb as(
2 select '河北' region,'11111111' class,400 money from dual union all
3 select '河北','13000003',600 from dual union all
4 select '河北','22222222',10000 from dual union all
5 select '上海','11000222',700 from dual union all
6 select '上海','20000345',300 from dual union all
7 select '上海','22222222',800 from dual)
8 select region,class,money
9 from (
10 select row_number() over (partition by region order by class) rn,
11 region,class,money
12 from tb)
13 where rn in (1,3)
14 /
REGION CLASS MONEY
------ -------- ----------
河北 11111111 400
河北 22222222 10000
上海 11000222 700
上海 22222222 800
select row_number() over (partition by region order by class) rn,
region,class,money
from tb
麻烦帮忙解释下吧
--这里不知道你的实际数据,这里只是取出了你给的数据的第一行和第三行
--按照分组排序获取一个行号
row_number() over (
partition by region--先按照region分组
order by class) --再按照class排序
oracle row_number分析函数