如果你的 1类 2类 3类
是数值类型的话,可以这样
select id, sum(1类),sum(2类),sum(3类)
from (
select id, 1类 ,0,0 from
tab_1 where lx=1类
union all
select id, 0,2类,0 from
tab_1 where lx=2类
union all
select id, 0 ,0,3类 from
tab_1 where lx=3类
) as temp
group by id
是数值类型的话,可以这样
select id, sum(1类),sum(2类),sum(3类)
from (
select id, 1类 ,0,0 from
tab_1 where lx=1类
union all
select id, 0,2类,0 from
tab_1 where lx=2类
union all
select id, 0 ,0,3类 from
tab_1 where lx=3类
) as temp
group by id
解决方案 »
- 一条sql语句 我写来不对 见鬼请大家帮我看看 谢谢
- 如何查询出某个字段的数据记录条数大于某个值?
- 900条记录左联接一张表,最终得出了700条记录,请各位路过的大侠帮忙呀,跪谢.
- 用户权限问题?急
- 验证一SQL语句(希望有更好的算法)
- 求助:关于ORACLE数据库介质恢复问题
- oracle 登录问题
- 搜了半天,都没找到答案,还是要问一下..
- oracle initialization or shutdown in progress 求助!急。
- 以下oracle中的语法表示什么意思?
- 关于我的未来。。。请各位高手和斑竹指点迷津。。
- ORACLE中,如果字段名刚好是关键字,select语句该怎么写?
(select sj from tab_l a where a.id=b.id and lx='2类') as 2类,
(select sj from tab_l a where a.id=b.id and lx='3类') as 3类
from tab_l b
(select sj from tab_l a where a.id=b.id and lx='2类') as 2类,
(select sj from tab_l a where a.id=b.id and lx='3类') as 3类
from tab_l b
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;