oracle统计sql
① oracle 关于统计的sql语句,求高人指点!!!
SELECT C_OPERATORS,
SUM(CASE WHEN C_OPERATORS = '移动' THEN 1
WHEN C_OPERATORS = '电信' THEN 1
WHEN C_OPERATORS = '联通' THEN 1
ELSE 0 END),
TO_CHAR(C_SEND_DATATIME,'YYYYMM')
FROM TABLE_NAME
GROUP BY C_OPERATORS;
② 统计一个字段的总数量sql语句,oracle数据库
select
count(*)
from
acc_exchange
where
(工商银行所在列名)='工商银行';
你的问题有歧义
INCOME_MONEY这个为列名吧,如果为某列的值,那么就应该是双过滤:
select
count(*)
from
acc_exchange
where
(工商银行所在列名)='工商银行'
and
(INCOME_MONEY所在列名)='INCOME_MONEY';
③ oracle 统计SQL
--试验用表
CREATETABLETABLE_DEMO(TIMEDATE,IDVARCHAR2(10),typeVARCHAR2(2),NUMVARCHAR2(10));
--试验数据
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'01','A','1');
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'0111','A','1');
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'0211','B','1');
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'0221','B','1');
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'0231','C','1');
INSERTINTOTABLE_DEMOVALUES(SYSDATE,'0311','A','1');
--统计的Sql
SELECTR.COUNT_TIME,R.COUNT_ID,R.TYPE,SUM(R.NUM)ASNUM
FROM(SELECTTO_CHAR(T.TIME,'yyyyMMdd')ASCOUNT_TIME,
SUBSTR(T.ID,0,2)ASCOUNT_ID,
T.TYPE,
T.NUM
FROMTABLE_DEMOT)R
GROUPBYR.COUNT_TIME,R.COUNT_ID,R.TYPE
ORDERBYR.COUNT_TIME,R.COUNT_ID,R.TYPE
④ oracle sql怎样统计数量
可以通过district来取出字段,之后通过count计算总数量。
sql:select count(district id) from tablename;
如果id字段没有空值的话,可以通过count统计字段的总数量(字段内容可能重复)。
sql:select count(id) from tablename;
⑤ Oracle数据分类统计的sql语句怎么写
好难写啊,感觉如果要实现你这个效果,可能得改一下表结构吧,反正我只能写成这样,你看能可以么。。。
select distinct number,分类,count(a.content) from(select number,a.content,分类 from a,b where a.content=b.content) group by number,分类 order by number,分类;
查出来效果是这样的
123 养生 1
123 祝福 1
213 幽默 2
213 祝福 1
⑥ oracle 表内做计算再统计的SQL语句怎么写 需要算的内容如下
select count(*)
from (select 人员编号,
sum(case
when 变动类型 = '新增' then
1
else
0
end) as 新增次数,
sum(case
when 变动类型 = '删除' then
1
else
0
end) as 删除次数
from ceshi
group by 人员编号)
where 新增次数 - 删除次数 = 1;
select max(时间), 人员编号
from ceshi
where 人员编号 in (select 人员编号
from (select 人员编号,
sum(case
when 变动类型 = '新增' then
1
else
0
end) as 新增次数,
sum(case
when 变动类型 = '删除' then
1
else
0
end) as 删除次数
from ceshi
group by 人员编号)
where 新增次数 - 删除次数 = 1)
group by 人员编号;
⑦ oracle统计查询 sql语句应该怎么写
select
substrb(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字段是字符型给出的,如果你的表中此字段是日期型,则进行一下转化
⑧ oracle sql 某字段 统计
WITHTTAS
(
SELECT1ASID,15ASCOUNTNUMFROMDUALUNIONALL
SELECT2ASID,12ASCOUNTNUMFROMDUALUNIONALL
SELECT3ASID,11ASCOUNTNUMFROMDUALUNIONALL
SELECT4ASID,16ASCOUNTNUMFROMDUALUNIONALL
SELECT5ASID,8ASCOUNTNUMFROMDUALUNIONALL
SELECT6ASID,20ASCOUNTNUMFROMDUAL
)
SELECTT1.ID,
T1.COUNTNUM,
WM_CONCAT(T2.ID)ASCOUNTNUM,
COUNT(T2.ID)ASGREATNUM
FROMTTT1
LEFTJOINTTT2
ONT1.COUNTNUM<T2.COUNTNUM
GROUPBYT1.ID,T1.COUNTNUM
ORDERBY1
有问题可以追问
⑨ 求Oracle分组统计数量的sql怎么写,需求如下
造了点数据,不知道是这个意思不
createtabletest
(totalint,
ssbmvarchar2(20));
insertintotestvalues(5,'02(5)');
insertintotestvalues(5,'02(5)');
insertintotestvalues(5,'04(5)');
insertintotestvalues(5,'04(5)');
insertintotestvalues(5,'03(5)');
commit;
查询:
selectssbm||'('||cnt||')'from(selectsubstr(ssbm,1,instr(ssbm,'(')-1)ssbm,count(*)cntfromtestgroupbysubstr(ssbm,1,instr(ssbm,'(')-1))t
结果: