获取计数假设我有一个表states
如下:两个不同的条件
create table states (id int4 unique not null, state int4 not null);
我想在其状态为1,表中的行数,并在表中的行数其状态2.两个单独的查询这样做很简单:
select count(*) from states where state = 1;
select count(*) from states where state = 2;
但似乎很傻要经过整个表的两倍。有人能想到一些聪明的伎俩,让我能够在一个声明中获得相同的信息,并且只通过一次表格吗?
我结束了使用你的第二个例子,谢谢! –