重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
WITH tmp AS
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、小程序制作、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了志丹免费建站欢迎大家使用!
(select '张一' as names, '2014年1月' as dates, '90' as sorcs from dual union
select '张四' as names, '2014年1月' as dates, '66' as sorcs from dual union
select '张一' as names, '2014年2月' as dates, '84' as sorcs from dual union
select '张二' as names, '2014年2月' as dates, '75' as sorcs from dual union
select '张四' as names, '2014年2月' as dates, '48' as sorcs from dual union
select '张三' as names, '2014年3月' as dates, '75' as sorcs from dual union
select '张四' as names, '2014年3月' as dates, '96' as sorcs from dual union
select '张一' as names, '2014年4月' as dates, '94' as sorcs from dual union
select '张四' as names, '2014年4月' as dates, '75' as sorcs from dual union
select '张三' as names, '2014年5月' as dates, '84' as sorcs from dual union
select '张四' as names, '2014年6月' as dates, '75' as sorcs from dual union
select '张二' as names, '2014年7月' as dates, '64' as sorcs from dual union
select '张一' as names, '2014年8月' as dates, '77' as sorcs from dual )
SELECT names,
SUM(CASE WHEN dates ='2014年1月' THEN sorcs END ) AS "2014年1月" ,
SUM(CASE WHEN dates ='2014年2月' THEN sorcs END ) AS "2014年2月",
SUM(CASE WHEN dates ='2014年3月' THEN sorcs END ) AS "2014年3月"
FROM tmp
GROUP BY names
你这个是要行列互换吧?
1、创建测试表,create table test_date(v_date date);
2、插入测试数据,
insert into test_date
select sysdate - level * 10 from dual connect by level 100
3、查询表中所有记录,select * from test_date,可以看到时间格式为年月日时分秒,
4、编写sql,将时间截取到年月,
select t.*,
to_char(v_date, 'yyyymm') v_date_mon1,
trunc(v_date, 'mm') v_date_mon2
from TEST_DATE t
excel自带的简单/完美的公式:
假设小日期在a1,大日期在a2,用公式
=datedif(a1,a2,"y")"年"datedif(a1,a2,"ym")"月"datedif(a1,a2,"md")"天"
就可以了。
select to_char(sysdate,'mm') from dual 是月份
select to_char(sysdate,'yyyy') from dual 是年份
select * from (select 除了时间所有字段写出来,to_date('COMMENTTIME','yyyy-mm-dd hh24:mi:ss') time from T_SCHOOL_RECORDCOMMENT where RECORDID = :p_cid) order by time desc;
这样试试,但是你的时间字段用该保存为date类型,这样好像很麻烦。。
这样不行,你想用范围分区,但是你这个写法意思是列表分区by
list
建议用范围分区,但是用logtime就行了,本身就是日期格式,本来就可以做比较