举例
with 表别名 as(select ....)
with a as(select SUM(1) as Number,SUM(case when CallSeconds<=0 then 0 else (CallSeconds/60) end) as Time,
substring(Content,len(Content)-3,4) as Servetypefrom Oca_CallService where Status=1 and
CONVERT(varchar(4),CheckInTime,120)='2014'
group by substring(Content,len(Content)-3,4))
select a.Number,a.Time,a.Servetype from a
union
select SUM(a.Number),sum(a.Time),'小计' Servetype from a
distinct 不重复函数
DATEDIFF() 函数返回两个日期之间的天数。
LTRIM(str) 返回字符串str的前导(左边)空格字符去掉。