select l.DQ,count(dbo.table1.usernumber) as counts from 
(select top 100 percent dq.id,dq.dq,lthd.hd from lthd,dq where lthd.dq=dq.dq group by dq.id,dq.dq,lthd.hd order by dq.id) as l,table1 
where l.HD=substring(usernumber,1,7) and dbo.table1.insertdate between @b_times and @a_times and OrderState=@dzyf group by l.DQ,l.id order by l.id查询的数据大概有100多万,用我的这个语句在网站里总是查询不出来,请高手指点。

解决方案 »

  1.   

    推荐你本书
    sql cookbook
      

  2.   

    你把最后的order by l.id 去掉试一下
      

  3.   

    是2个 order by 都去掉
      

  4.   

    唉. 其实我也知道仅仅select应该也优化不到哪儿去. 好的. 谢谢
      

  5.   

    很少见 oracle 用 sys 或者 system 帐户的, 但是经常见到 sql server 使用 sa 帐户的说明了什么呢?
      

  6.   

    句子是错的吧select l.DQ,count(dbo.table1.usernumber) as counts from l.dq是很多行,count(dbo.table1.usernumber)就1行,怎么查?你知道放到MSSQL里查,肯定报错
      

  7.   

    在insertdate 上面作索引,把dbo.table1.insertdate between @b_times and @a_times  放到 where 后面的第一个位置。count(dbo.table1.usernumber) 可以改成count(*)
      

  8.   


    select A.DQ,count(B.usernumber) as counts from 
    (select DISTINCT dq.id,dq.dq,lthd.hd from lthd,dq where lthd.dq=dq.dq ) A ,table1 B
    where A.HD=substring(B.usernumber,1,7) and B.insertdate between @b_times and @a_times and B.OrderState=@dzyf group by A.DQ OrderState是那个表的?
      

  9.   

    count(dbo.table1.usernumber) 可以改成count(*)这个正解!  想来是索引的问题,count(*)直接找id