求助,关于统计的SQL语句的优化?
在线求助SQL优化:Select series,xValue,sum(yValue) AS yValue From (
SELECT 1 as series,0 As Version,Convert(varchar(2),datepart(m,AnalyseDate))+'.'+Convert(varchar(2),datepart(dd,AnalyseDate)) As xValue,Total As yValue
FROM dbo.IPTV_USER_LoginAnalyse WHERE AnalyseType = 3 AND [Type] = 2 AND Analysedate between '2008-08-22 00:00:00' and '2008-09-09 23:59:59'
Union All
SELECT 2 as series,0 As Version,xValue,Count(1) AS yValue FROM(
SELECT distinct userid,Convert(varchar(2),datepart(m,RowTime))+'.'+Convert(varchar(2),datepart(dd,RowTime)) As xValue FROM IPTV_FISH_HISTORY
Where RowTime between '2008-08-22 00:00:00' and '2008-09-09 23:59:59') a
Group by xValue
Union All
SELECT 3 as series,0 As Version,xValue,Count(1) AS yValue FROM(
SELECT ID,Convert(varchar(2),datepart(m,RowTime))+'.'+Convert(varchar(2),datepart(dd,RowTime)) As xValue FROM IPTV_FISH_HISTORY
WHERE Status = 1 AND RowTime between '2008-08-22 00:00:00' and '2008-09-09 23:59:59') a
Group by xValue
) AS x group by series,xValue