数据库统计不同字段数量时的sql语句

来源:互联网 发布:linux安装多个jdk版本 编辑:程序博客网 时间:2024/05/16 12:50

今天对一个表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

0 1
原创粉丝点击