例: stu表:
school class nation total ...
清华 1班 汉族 35
清华 2班 汉族 30
清华 2班 回族 3
清华 2班 藏族 2
北大 1班 壮族 35
结果:
school class nation ...
清华 1班 汉族
2班 回族
汉族
藏族
北大 1班 壮族
school class nation total ...
清华 1班 汉族 35
清华 2班 汉族 30
清华 2班 回族 3
清华 2班 藏族 2
北大 1班 壮族 35
结果:
school class nation ...
清华 1班 汉族
2班 回族
汉族
藏族
北大 1班 壮族
解决方案 »
- 怎么将SQL SERVER中的数据导入到ORACLE中去
- 好急 关于oracle10G 数据库链接问题
- 诚聘IFS之ORACLE技术顾问,待遇自己谈,有兴趣者进
- 急求 oracle 中如何取消用户登陆次数限制,而不被锁定?
- Oracle存储过程中的问题
- 关于索引的一个问题
- oracle8.1.6能否安裝在win2000上?急救?
- 我写的求按某个字段(CHAR型)的排序后的最大一条记录竟然如此麻烦,select * from (select * from tablename order by to_number(field1) d
- 日期格式问题
- 可否讨论一下Oracle的各个版本。
- 如何优化一段sql
- add debug information
1 北大 1班 35
2 清华 1班 35
3 清华 2班 35
4 清华 2班 35
5 清华 2班 35想把重复的合并 用sql来实现不现实 就算费劲写出来 效率也不高
这个要在程序里边处理才对,从技术角度看,从逻辑角度看,都应该这样
SELECT '清華' AS school,'1班' as classs,'漢族' as nation,'35' as total from dual
union all
SELECT '清華' AS school,'2班' as classs,'漢族' as nation,'30' as total from dual
union all
SELECT '清華' AS school,'2班' as classs,'回族' as nation,'3' as total from dual
union all
SELECT '清華' AS school,'2班' as classs,'藏族' as nation,'2' as total from dual
union all
SELECT '北大' AS school,'1班' as classs,'壮族' as nation,'35' as total from dual
)
select case when school = ps then '' else school end as school,
case when classs = pc then '' else classs end as classs,
nation,
total from(
select lag(school)over(partition by school order by school) as ps,lag(classs)over(partition by school order by school,classs) as pc,test.* from test)=================================================
1 清華 1班 漢族 35
2 2班 漢族 30
3 回族 3
4 藏族 2
5 北大 1班 壮族 35