数据库统计不同字段数量时的sql语句,字段数量sql语句
今天对一个表A中字段进行查询,不同类型的字段进行数据统计;
1.select count(1) from A where strwhere 对符合条件的行数进行统计
2.select count(filed) from A where strwhere 对符合条件列的行数进行统计,基本同上
下面才是今天重头戏
3.当字段存在类型,且为0,1时,最为简单,但常用如:1.男,女;2.是,否;等可以用 0,1来作为类型的正反类型时;
select sum(filde1),sum(filde2) from A where strwhere
当 查询多个字段,且为固定类型时(typeA,typeB。。。。)
4. select sum(case when filed1=typeA1 then 1 else 0 end),sum(case when filed2=typeA2 then 1 else 0 end) from A where strwhere
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。