简单SQL语句
详细讲解语句的正确运用:
(以SUM语句为列子)
注:select starttime 开始时间 ,endtime 结束时间,calltype 通话类型(calltype=1代表长话,calltype=0代表市话),accountbillid 帐单ID
from call
1、市话:select sum(ceiling (datediff(ss,starttime,endtime)/60.0)) "通话时长" from call
where phonenumber='13101337079'and(starttime between '2008-8-1 00:00:00' and '2008-8-31 23:59:59') and calltype=0
2、长话:select sum(ceiling (datediff(ss,starttime,endtime)/60.0)) "通话时长" from call
where phonenumber='13101337079'and(starttime between '2008-8-1 00:00:00' and '2008-8-31 23:59:59') and calltype=1
3、select sum(ceiling(datediff(ss,call.starttime,call.endtime)/60.0)*tariffrate) as 话费
from call , tariffrate
where call.calltype =tariffrate.calltype and phonenumber ='13101337079' and (starttime between '2008-8-1 00:00:00'and '2008-8-31 23:59:59')
4、select datepart(day,paytime)日期 , sum(charge)合计费用
from "history-accountbill"
where ispaid<>0 and (paytime between '2008-6-1 00:00:00'and '2008-6-30 23:59:59 ')
group by datepart(day,paytime)
having sum(charge)>=3000
order by datepart(day,paytime)
更多的SQL语句运用,可以关注我们学校的网站,里面会有你们所需要的:HTTP://bdqn1.com |