獲取計數假設我有一個表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;
但似乎很傻要經過整個表的兩倍。有人能想到一些聰明的伎倆,讓我能夠在一個聲明中獲得相同的信息,並且只通過一次表格嗎?
我結束了使用你的第二個例子,謝謝! –