如何提高SQL语句查询速度 - MS-SQL Server / 基础类
数据库为:sql server
我现在有这样的一条SQL语句:表中现有数据8万左右
select distinct des,
(select count(*) from baseinfo as a where a.des=b.des and(jjgz='1' or jjgz='2') ) as count1,
(select count(*) from baseinfo as a where a.des=b.des and jjgz is not null ) as count2,
case when (select count(*) from baseinfo as a where a.des=b.des and jjgz is not null )=0
then 0
else (cast(cast((select count(*) from baseinfo as a where a.des=b.des and(jjgz='1' or jjgz='2') ) as float)/(
select count(*) from baseinfo as a where a.des=b.des and jjgz is not null ) as decimal(18,6)) )*100 end as cout1
from baseinfo as b where 1=1 order by cout1 desc
在查询的时候用时6秒。
同时也为该字段建了索引,也没有提高查询速度。
请问各路高手,我该如何优化下呢?让查询速度变的快点。
改嵌套为连接...
1楼可否说的在明白些?
把嵌套改为连接的方式应该会有所提高。
后面的嵌套都按照这样的改
学习.
你这个也太复杂了吧,两种办法提高效率:
1、修改你的设计,减少这么复杂的连接,子查询等
2、使用存储过程
学习 帮顶
你这个sql写的够烂的,
这个似乎和之前问过的一个很像,
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......