两条不解的sql 求各位解答
SELECT count(*) from (SELECT uuid,create_date from tbb_api_access WHERE create_date > '2012-02-17' GROUP BY uuid) as t
SELECT count(*) from (SELECT id,create_date from tbb_api_access GROUP BY uuid) as t WHERE create_date > '2012-02-17'
这条sql在执行结果上为什么会有差异?
------解决方案--------------------如果表tbb_api_access只有一条记录
uuid,create_date
1, '2012-02-11'
则你可以看到(SELECT uuid,create_date from tbb_api_access WHERE create_date > '2012-02-17' GROUP BY uuid) 返回是空
而(SELECT id,create_date from tbb_api_access GROUP BY uuid) 是 1,'2012-02-11'
------解决方案--------------------理解一下WHERE的执行顺序。
------解决方案--------------------结果一样吧
------解决方案--------------------一个是先WHERE再GROUP
另一个是先GROUP再WHERE