【发布时间】:2010-10-29 14:37:05
【问题描述】:
大家好,如果这个问题太简单了,请原谅我。我基本上想要一个数据库中男性和女性的数量。所以我知道两个简单的查询可以完成这个,例如:
select count(*) from table where gender='male'
select count(*) from table where gender='female'
但是,这似乎非常低效,因为我知道下面的查询都是同一个查询:
select count(*) from table where gender='female'
select count(*) from table where gender<>'male'
是否有一种最佳方式来检索此信息,而不必遍历数据库中的每一行两次?
【问题讨论】:
-
我发现你的问题很有趣 :-)
标签: sql database count query-optimization