1.这是 user_name 表
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
写一个sql (要求 用 lead over 这些 分析 函数 为了 提高 效率)实现 下面的 效果 year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4 oraclesql
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
写一个sql (要求 用 lead over 这些 分析 函数 为了 提高 效率)实现 下面的 效果 year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4 oraclesql
解决方案 »
- socket链接本地外网出现超时,是怎么回事 [Java Java相关]
- struts2+jfreechart如何生成热点图片
- 救命啊~寻求一个异常的解决方法。
- hibernate.cfg.xml编码
- 关于在frameset中使用servlet的问题
- 大家讨论下,在成都做J2EE的,一个月能拿到多少喃?
- Struts中的validator如何用
- 求教如何在浏览器后退时过滤器仍起作用
- 小弟刚学struts,碰到入门的问题:我的struts为什么总提示HTTP Status 503 - Servlet action is currently unavailable?
- 急....上传附件是否...
- struct中@Result注解的问题
- 关于SPRING3.0整合STRUTS2
(
select 1991 year,1 month,1.1 amount from dual
union all
select 1991 year,2 month,1.2 amount from dual
union all
select 1991 year,3 month,1.3 amount from dual
union all
select 1991 year,4 month,1.4 amount from dual
union all
select 1992 year,1 month,2.1 amount from dual
union all
select 1992 year,2 month,2.2 amount from dual
union all
select 1992 year,3 month,2.3 amount from dual
union all
select 1992 year,4 month,2.4 amount from dual
)
select * from temp
PIVOT (SUM(amount) FOR month IN (1 as m1,2 as m2,3 as m3,4 as m4) ) YEAR M1 M2 M3 M4
---------- ---------- ---------- ---------- ----------
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.411G的行转列可以用这个方式
如果是10g还是老实的用decode吧
为啥要用分析函数,谁告诉你用了就能提高效率?
我以前的sql 语句是select distinct year,
(select amount from user_name where amount=1 and user_name.year=b.name ) m1,
(select amount from user_name where amount=2 and user_name.year=b.name ) m2,
(select amount from user_name where amount=3 and user_name.year=b.name ) m3,
(select amount from user_name where amount=4 and user_name.year=b.name ) m4,
from user_name b
老板要我优化 这个 sql 了
所以 我就 想的 用 分析函数 了
子查询 效率 确实 不怎么 效率 高 ,大数据量的 话 这个 太影响 性能 了。
如果嫌弃数据速度太慢你可以在页面加载的时候启动一个线程把你的数据插入到你自定义的datatable中这个datatable就可以用刚刚2楼的说法去做就好了
可以先用 group by 月份,
然后程序里就好做了!
这种问题我们都碰到 过!
如果是10g还是老实的用decode吧
为啥要用分析函数,谁告诉你用了就能提高效率?