oracle统计查询 sql语句应该怎么写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle统计查询 sql语句应该怎么写相关的知识,希望对你有一定的参考价值。
selectsubstrb(create_time,1,4)
"年份",
sum(decode(substrb(create_time,6,2),'01',commission,0))
"1月",
sum(decode(substrb(create_time,6,2),'02',commission,0))
"2月",
sum(decode(substrb(create_time,6,2),'03',commission,0))
"3月",
sum(decode(substrb(create_time,6,2),'04',commission,0))
"4月",
sum(decode(substrb(create_time,6,2),'05',commission,0))
"5月",
sum(decode(substrb(create_time,6,2),'06',commission,0))
"6月",
sum(decode(substrb(create_time,6,2),'07',commission,0))
"7月",
sum(decode(substrb(create_time,6,2),'08',commission,0))
"8月",
sum(decode(substrb(create_time,6,2),'09',commission,0))
"9月",
sum(decode(substrb(create_time,6,2),'10',commission,0))
"10月",
sum(decode(substrb(create_time,6,2),'11',commission,0))
"11月",
sum(decode(substrb(create_time,6,2),'12',commission,0))
"12月"
from
test
group
by
substrb(create_time,1,4)
此语句是按create_time字段是字符型给出的,如果你的表中此字段是日期型,则进行一下转化 参考技术A 您的统计查询是指统计函数吗?还是指查询统计信息?
oracle的统计函数有很多,如sum、row_number,一般都是结合group
by来用,例如:
SELECT
PRODUCT_ID,
SUM(SALES)
FROM
SALES_TABLE
GROUP
BY
PRODUCT_ID;
如果要一次按照多个维度做统计,可以使用over子句,如:
SELECT
SUM(SALES)
OVER
(PARTITION
BY
PRODUCT_ID)
SALES_BY_PRODUCT,
AVG(QUANTITY)
OVER
(PARTITION
BY
DEPARTMENT_ID)
QUANTITY_BY_DEPARTMENT
FROM
SALES_TABLE
另外,在group
by里面,还有roll
up、cube等子句
如果是查询统计信息,可以参照以下视图:
SELECT
VIEW_NAME
FROM
DBA_VIEWS
WHERE
VIEW_NAME
LIKE
'%STAT%'; 参考技术B oracle查询语句:
select
字段名
from
表名
(where
判断条件);
oracle的统计函数(count)
select
count(字段名),字段1,字段2
from
表名
(where
判断条件)
group
by
字段1,字段2; 参考技术C 1、首先你要把某一年的条件查询出来
2、把年度的条件作为子查询再查询出这一年的月份
3、再根据月份查询出这一月份的营业额
以上是关于oracle统计查询 sql语句应该怎么写的主要内容,如果未能解决你的问题,请参考以下文章