在我的数据库表我有一个容纳两列0或1MYSQL计数功能合并
我有type
和Gender
,其中类型是指0 => teacher
和1 => student
和性别:0 => male
和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
它可以在一个查询做什么?如果是这样,怎么样?
感谢你,工作很好 –