| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1026 人关注过本帖
标题:求助,关于统计的SQL语句的优化?
取消只看楼主 加入收藏
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
结帖率:100%
收藏
 问题点数:0 回复次数:1 
求助,关于统计的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
搜索更多相关主题的帖子: SQL 语句 统计 
2008-09-04 17:02
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
收藏
得分:0 
迅雷上面有下载。
分别在UserID_RowTime_Status,Analysedate_AnalyseType_Type,Analysedate,AnalyseType,Type上建了索引,查询百万条数据,速度从1万6提高到8千,还有能优化的地方请不吝指教一下,谢谢了。

好累
2008-09-05 02:15
快速回复:求助,关于统计的SQL语句的优化?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049016 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved