SQL Basic
SQL 基础教程 /(日) MICK 著;孙淼,罗勇译.
# DISTINCT 和 GROUP BY
DISTINCT 和 GROUP BY 子句,都能够删除后续列中的重复数据。除此之外,它们还都会把 NULL 作为一个独立的结果返回。其实不仅处理结果相同,执行速度也基本上差不多(它们都是数据的内部处理,都是通过排序处理来实现的),那么到底应该使用哪一个呢?
这个问题本身就是本末倒置的,我们应该考虑的是该 SELECT 语句是否满足需求。选择的标准其实非常简单,在 “想要删除选择结果中的重复记录” 时使用 DISTINCT,在 “想要计算汇总结果” 时使用 GROUP BY。不使用...
more...