oracle分表如何平均 oracle数据库分表怎么实现

oracle 中如何用avg函数求出3个月的平均费用三个月 , 每月的平均:
select 月份,avg(sum(charge)) from 费用 where 时间 between 1月 and 3月 group by 月份
三个月的总平均:
select avg(sum(charge)) from 费用 where 时间 between 1月 and 3月
关于oracle平均数给你简单写一下
数据及表
create table test(tag_date varchar2(8),
tag_time varchar2(6),
tag01 number(4,1));
insert into test values ('20130818','000210',26.7);
insert into test values ('20130818','000440',26.7);
insert into test values ('20130818','000710',26.7);
insert into test values ('20130818','000940',26.8);
insert into test values ('20130818','001210',26.8);
insert into test values ('20130818','001440',26.8);
insert into test values ('20130818','001710',26.8);
insert into test values ('20130818','001940',26.8);
insert into test values ('20130818','003210',26.8);
insert into test values ('20130818','003440',26.8);
insert into test values ('20130818','003710',26.8);
insert into test values ('20130818','003940',26.7);
执行
select a.tag_date,avg(a.tag01) from
(select ceil(rownum/4) rn,test.* from test) a
group by a.tag_date,a.rn;
结果截图
简单给你说明一下
(select ceil(rownum/4) rn,test.* from test) a
这个就是用行号除以4向上取整 , 比如1/4 2/4 3/4 4/4 最终取到的整数都是1,所以这样就能把4个分成一组了,当5/4 6/4..这样取到的整数就是2了
你这个插入顺序如果比较错乱的话
可以改成
row_number() over (order by tag_date||tag_time) 这样的形式
还有,你可以把括号里那句单独拿出来执行一下,看下结果,大概就知道什么意思了
ORACLE中如果计算每日的平均值select MG_ID,trunc(TIME,'dd') statDay,avg(FEED_IN_POWER) feedAvg from tableName group by MG_ID,trunc(TIME,'dd')
oracle查询按记录个数,按比例汇总后求平均值可以参考如下:
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
【oracle分表如何平均 oracle数据库分表怎么实现】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;
oracle中如何求平均数的和?即avg函数和sum函数的套用你这个如果不分组的话,两个值应该是相同的,求出来的占比得到的结果是1
oracle 取平均值你好,如果格式都如你贴图的一样的话可以用这种最笨的方式全一个个化成数值型 , 然后相加取值 。
select CHECK_NORM,
(to_number(substr(CHECK_INFO, 1, 4))
to_number(substr(CHECK_INFO, 6, 4))
to_number(substr(CHECK_INFO, 11, 4))
to_number(substr(CHECK_INFO, 16, 4))
to_number(substr(CHECK_INFO, 21, 4))
to_number(substr(CHECK_INFO, 26, 4))
to_number(substr(CHECK_INFO, 31, 4))
to_number(substr(CHECK_INFO, 36, 4))
to_number(substr(CHECK_INFO, 41, 4))
to_number(substr(CHECK_INFO, 46, 4))) / 10
from 表名;
如果格式不统一,建议如2楼的,把字符型中的‘/’全部替换成‘ ’,然后拼接出来一个sql,执行处理 。
望采纳,谢谢 。
关于oracle分表如何平均和oracle数据库分表怎么实现的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读