在我的数据库表中,我有两列分别为 0 或 1。
我有type
and Gender
,其中 type 表示0 => teacher
and1 => student
表示性别:0 => male
and 1 => female
。
如何编写单个 sql 查询来获取教师、学生、男性和女性的数量?
现在我有:
select COUNT(type) as teachers from my_table where type = 0; // Teachers
select COUNT(type) as students from my_table where type = 1; // Students
select COUNT(gender) as males from my_table where type = 0; // Males
select COUNT(gender) as females from my_table where type = 1; // Females
可以在一个查询中完成吗?如果是这样,怎么做?