合并sql语句

select aa, Count(bb) from tablename group by aa

select aa, Count(bb) from tablename where cc>=20021001
and cc<= 20021031 group by aa

如何将两个检索结果放在一条语句中实现
---------------------------------------------------------------

如果你的MySQL是4.0.0以上的版本,
你就可以使用 UNION 来实现了,

---------------------------------------------------------------

up
gz
!!!!
---------------------------------------------------------------

select aa, Count(bb) from tablename group by aa

union

select aa, Count(bb) from tablename where cc>=20021001
and cc<= 20021031 group by aa

使用union要注意两个结果的列数相同。

Published At
Categories with 数据库类
comments powered by Disqus