select distinct f1 from db.table
where 1=1 
and f1>400001如果表数据很多,这个语句在mysql里,上面是需要很长时间才出结果的select distinct f1 from db.table 这个语句是很快出结果的这说明,mysql5.0没有对这种语句的查询优化。所以,就得写成
select 
from 
(
  select dis....
)
where 
的子句形式
请问,sqlserver里对这种语句有内置的优化吗?

解决方案 »

  1.   

    mysql里上面的子句也是很慢,mysql真烂。how
      

  2.   

    msyql好像也有,我过了一阵再执行
    select distinct f1 from db.table
    where 1=1 
    and f1>400001速度,就快了,可能数据库刚才很忙来着。
      

  3.   

    试试这样
    select distinct...
    from 
    (
      select ....where...
    )
      

  4.   

    select distinct f1 from db.table
    where 1=1 --應該去掉
    and f1>400001
    最好不要像這樣寫,那樣只是方便了前台動態組合SQL語句
    但是性能很差。
    應該將主鍵或索引字段排在where 語句的最左邊。
    如下:
    select distinct f1 from db.table
    where f1>400001