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里对这种语句有内置的优化吗?
where 1=1
and f1>400001如果表数据很多,这个语句在mysql里,上面是需要很长时间才出结果的select distinct f1 from db.table 这个语句是很快出结果的这说明,mysql5.0没有对这种语句的查询优化。所以,就得写成
select
from
(
select dis....
)
where
的子句形式
请问,sqlserver里对这种语句有内置的优化吗?
select distinct f1 from db.table
where 1=1
and f1>400001速度,就快了,可能数据库刚才很忙来着。
select distinct...
from
(
select ....where...
)
where 1=1 --應該去掉
and f1>400001
最好不要像這樣寫,那樣只是方便了前台動態組合SQL語句
但是性能很差。
應該將主鍵或索引字段排在where 語句的最左邊。
如下:
select distinct f1 from db.table
where f1>400001