遇到一个问题,来请教大家,我用oracle联表查询做统计,出来的结果是这样的
code state count(state)
3310 on 13
3310 off 2
我现在想把这个结果转换成一列,像下面这样
code on off
3310 13 2
不知道有没有办法做到,知道的大哥帮忙说下,万分感谢啊
code state count(state)
3310 on 13
3310 off 2
我现在想把这个结果转换成一列,像下面这样
code on off
3310 13 2
不知道有没有办法做到,知道的大哥帮忙说下,万分感谢啊
max(case when state ='on' then count else 0 end) on,
max(case when state ='off' then count else 0 end) off
from 表
group by codeselect code,
max(decode(state,'on',count,0)) on,
max(decode(state,'off',count,0)) off
from 表
group by code