大型数据库。。。

来源:百度知道 编辑:UC知道 时间:2024/09/20 07:10:43
select yyyymmdd,
sum(decode(keywordid,110,amount,0)) mms,
sum(decode(keywordid,120,amount,0)) charge,
sum(decode(keywordid,130,amount,0)) emoticon,
sum(decode(keywordid,140,amount,0)) sms,
sum(decode(keywordid,190,amount,0)) turnoff
from (select to_char(requesttime,'yyyymmdd')
yyyymmdd,keywordid,
count(*) amount
from txhistory
group by to_char(requesttime,'yyyymmdd'),keywordid)
group by yyyymmdd

请帮我解释一下这段是什么意思吧 呵呵 希望详细到每一句 谢谢。。真的

sum()聚合函数和group by 一起用
decode() 想当于if else 或 case when
count(*) 记录个数
to_char 转成字符
还哪不懂HI我

首先
select to_char(requesttime,'yyyymmdd')
yyyymmdd,keywordid,
count(*) amount
from txhistory
group by to_char(requesttime,'yyyymmdd'),keywordid
是统计每天keywordid的流量或数量.

然后
select yyyymmdd,
sum(decode(keywordid,110,amount,0)) mms,
sum(decode(keywordid,120,amount,0)) charge,
sum(decode(keywordid,130,amount,0)) emoticon,
sum(decode(keywordid,140,amount,0)) sms,
sum(decode(keywordid,190,amount,0)) turnoff
from (select to_char(requesttime,'yyyymmdd')
yyyymmdd,keywordid,
count(*) amount
from txhistory
group by to_char(requesttime,'yyyymmdd'),keywordid)
group by yyyymmdd;
只对keywordid 为 110 ,120 , 130 , 140 , 190 时,再进行累计,
如sum(decode(keywordid,110,amount,0)) mms 意思是keywordid为110时
取它的彩信条数出来 , 不为110时则为0 ,然后合计即SUM()