合并sql语句?
下面有2个sql,很简单:
select count(*) from a
select count(*) from a where id = 1
能不能使用一条语句实现上面的2条语句的功能,即同时查询所有的记录条数和符合某一条件的记录条数?
谢!
[解决办法]
select count(*),sum(case id when 1 then 1 else 0 end) from a
[解决办法]
select count(*) from a
union all
select count(*) from a where id = 1
[解决办法]
select count(*),num = (select count(*) from a where id = 1) from a