十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
分数太少了。
成都创新互联是一家专注于成都做网站、成都网站设计与策划设计,平罗网站建设哪家好?成都创新互联做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:平罗等地区。平罗做网站价格咨询:13518219792
select to_char(tm,'yyyy')||to_char(case when to_number(to_char(tm,'mm')) = 10 then 1 when to_number(to_char(tm,'mm')) 10 and to_number(to_char(tm,'mm')) = 20 then 2 else 3 end) aaa,avg(avgv) avgv
from tab
where tm ............. -- where条件
group by to_char(tm,'yyyy')||to_char(case when to_number(to_char(tm,'mm')) = 10 then 1 when to_number(to_char(tm,'mm')) 10 and to_number(to_char(tm,'mm')) = 20 then 2 else 3 end)
可以参考如下:
CREATE TABLE TEMP_AVG_SCORE
(T_DATA DATE,
T_NAME VARCHAR2(10),
T_SCORE NUMBER(10)
) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-01-01','YYYY-MM-DD'),'A',30) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-01-10','YYYY-MM-DD'),'A',40) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-01-15','YYYY-MM-DD'),'A',35) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-02-01','YYYY-MM-DD'),'B',120) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-02-10','YYYY-MM-DD'),'B',130) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-02-15','YYYY-MM-DD'),'B',150) ;
INSERT INTO TEMP_AVG_SCORE VALUES (TO_DATE('2015-02-20','YYYY-MM-DD'),'B',140) ;
COMMIT;
SELECT T.T_NAME 人员,
AVG(CASE
WHEN TO_CHAR(T.T_DATA, 'MM') = '01' AND T.NUM = 3 THEN
CASE
WHEN RN = 1 THEN
T.T_SCORE * 120 / 100
WHEN RN = 2 THEN
T.T_SCORE * 100 / 100
ELSE
T.T_SCORE * 80 / 100
END
WHEN TO_CHAR(T.T_DATA, 'MM') = '01' AND T.NUM = 4 THEN
CASE
WHEN RN = 1 THEN
T.T_SCORE * 120 / 100
WHEN RN = 2 THEN
T.T_SCORE * 110 / 100
WHEN RN = 3 THEN
T.T_SCORE * 90 / 100
ELSE
T.T_SCORE * 80 / 100
END
ELSE 0
END) 一月份,
AVG(CASE
WHEN TO_CHAR(T.T_DATA, 'MM') = '02' AND T.NUM = 3 THEN
CASE
WHEN RN = 1 THEN
T.T_SCORE * 120 / 100
WHEN RN = 2 THEN
T.T_SCORE * 100 / 100
ELSE
T.T_SCORE * 80 / 100
END
WHEN TO_CHAR(T.T_DATA, 'MM') = '02' AND T.NUM = 4 THEN
CASE
WHEN RN = 1 THEN
T.T_SCORE * 120 / 100
WHEN RN = 2 THEN
T.T_SCORE * 110 / 100
WHEN RN = 3 THEN
T.T_SCORE * 90 / 100
ELSE
T.T_SCORE * 80 / 100
END
ELSE
END) 二月
FROM (SELECT A.T_DATA,
A.T_NAME,
A.T_SCORE,
ROW_NUMBER() OVER(PARTITION BY A.T_NAME ORDER BY A.T_DATA DESC) RN,
B.NUM
FROM temp_avg_score A
LEFT JOIN (SELECT T_NAME, COUNT(1) NUM
FROM temp_avg_score
GROUP BY T_NAME) B ON A.T_NAME = B.T_NAME) T
GROUP BY T.T_NAME;
select month_no,avg(value) vag_value,max(value) max_value,min(value) min_value from table_name where substr(month_no,1,4)='{year}' group by month_no
{year}是年参数,month_no是月份参数,varchar2型,如果是时间类型,比如load_timeselect to_char(load_time,'yyyymm') month_no,avg(value) vag_value,max(value) max_value,min(value) min_value from table_name where to_char(load_time,'yyyy') ='{year}' group by to_char(load_time,'yyyymm')
写个大概意思,毕竟我并不知道你的表结构是什么样的。
你的表格是什么样的,特别是回见结构,如果是“年月日时分秒”结构的,那么首先单独截取"时"(不是截取年月日时,而是单独截取时),截取范围是4,这样出来的结果是每天0-4点的所有值。
然后开始考虑分组,你说的是每年每月的平均值,那么分组应该是“年月”,然后再avg一下你要平均的值应该就可以了。
三个月,每月的平均:
select 月份,avg(sum(charge)) from 费用 where 时间 between 1月 and 3月 group by 月份
三个月的总平均:
select avg(sum(charge)) from 费用 where 时间 between 1月 and 3月