求一SQL写法,写了许多不成功
数据库表结构:
id sex zt
1 男 1
2 女 0
3 女 1
4 女 1
5 女 1
6 男 0
需要得出 (zt=1)
count1 count2
男 1
女 2
[解决办法]
select count1=(select count(*) from tablename where sex= '男 ' and zt= '1 '),count2=(select count(*) from tablename where sex= '女 ' and zt= '1 ')
[解决办法]
select sex as count1,count(*) as count2,zt from qw group by sex,zt having zt=1
[解决办法]
我比较菜,select sex as count1,count(*) as count2,zt from qw group by sex,zt having zt=1
写在一行我不会
能提个意见么 性别=Gender 比较好
[解决办法]
select sex ,count(*) from table where zt=1 gorup by sex
[解决办法]
SELECT sex,count(sex)
FROM Table
where zt= "1 "
group by sex
[解决办法]
select sex as count1,count(sex) as count2
from hunman
where zt = "1 "
group by sex
[解决办法]
select count(*) as c1,sum(case sex when '男 ' then 1 else 0 end ) as c2,sum(case sex when '女 ' then 1 else 0 end ) as c3 from 表名 where zt=1
出来的就是 4 1 3