SQL中,where 与 having 的性能比较
原文:http://blog.csdn.net/showshore/article/details/7263115
---------------------------------------------------------
在做項目的過程中,使用sql語句時,很多時候會用到where或having。
看到國外一個論壇上有人提到兩者性能比較的這個問題時,有人是這樣回答的:
The theory (by theory I mean?SQL Standard) says that WHERE restricts the result set before returning rows and HAVING restricts the result set after bringing all the rows. So WHERE is faster. On SQL Standard compliant DBMSs in this regard, only use HAVING where you cannot put the condition on a WHERE (like computed columns in some RDBMSs.)
也就是說(從理論上講),where是在查詢前做條件限制,having是在查詢后的結(jié)果集上做條件限制。查詢前做限制的話,返回的件數(shù)會少;而在查詢后的結(jié)果集上做限制的話,之前的查詢結(jié)果可能會很多,這樣就會影響性能。
所以,一般是用where,having是在where不方便或者不能使用的情況下才使用。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的SQL中,where 与 having 的性能比较的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 内存 四_java最终化的内存
- 下一篇: targetFilterLifecycl