我通常通過psycopg2執行中的PostgreSQL 9.1順序如下SQL查詢每隔幾秒鐘:PostgreSQL的多個計數(),其中在一個單一的查詢條件
select count(type) from bag where type= 'fruit';
select count(type) from bag where type= 'vegtable';
select count(type) from bag where type= 'other';
select count(type) from bag where type= 'misc';
是否有可能做同樣的事情在一個單一的選擇查詢,以便即使該計數爲零,我也可以獲得每種類型的計數。如果給定的類型有零時,它給了我零計數,下面的工作將會起作用。
select type, count(*) from bag group by type;
謝謝
我在最後按類型拋出了一個命令,這正是我想要的。謝謝。 – user2695222