哪一句快一点
结果是一样的,用一个简单的例子第一句
SELECT '姓名' AS 名称, COUNT(*) AS 合计
FROM mytable
UNION ALL
SELECT name, COUNT(*) AS aa
FROM mytable GROUP BY name
第二句
SELECT '姓名' AS 名称, sum(aa) AS 合计
FROM (SELECT name, COUNT(*) AS aa
FROM mytable GROUP BY name) AS d
UNION ALL
SELECT name, COUNT(*) AS aa
FROM mytable GROUP BY name