我通常通过psycopg2在PostgreSQL 9.1中顺序执行以下SQL查询,每隔几秒钟执行一次:
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;
谢谢您。