表 table1
id name type hours
100 james 正常 2
100 james 周末 3
100 james 假日 1
101 jack 正常 2
101 jack 周末 3
如何分組變成
id name 正常 周末 假日 total
100 james 2 3 1 6
101 jack 2 3 5
id name type hours
100 james 正常 2
100 james 周末 3
100 james 假日 1
101 jack 正常 2
101 jack 周末 3
如何分組變成
id name 正常 周末 假日 total
100 james 2 3 1 6
101 jack 2 3 5
解决方案 »
- 纠结了我2天的问题,ORACLE正式库倒测试库密码问题
- 大家说这种insert语句要怎样写简单哦
- 请教个sql,排序的问题
- 还是关于ora-12514问题解决
- sql中的笛卡尔积问题
- java.sql.SQLException: ORA-00903: 表名无效(急呀!不知道为什么)
- 关于序列的问题
- 我在安装ORACLE 9i 3CD的那张碟中,出现了一个这种错误。我无法解决
- 用pro c写的一个集成访问数据库的动态库(属于16位版本)。访问Oracle8i以下的版本没问题,访问Oracle8i以上版本出错,请教是什么原因?
- oracle 递归
- 求:在一个表中查找A列最大值,B列最小值,并只返回一条记录的最优方法
- 大家看看这句sql语句有问题吗?
max(decode(type,'周未',hours)) col2,
max(decode(type,'假日',hours)) col3,
sum(hours) from combiancol group by id,name
select id, name,
sum(case type when '正常' then hours else null end) 正常,
sum(case type when '周末' then hours else null end) 周末,
sum(case type when '假日' then hours else null end) 假日,
sum(hours) total
from table1
group by id,name