入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

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

创建时间:2015-02-01 投稿人: 浏览次数:11307

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

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像