sql统计类代码 select type,count(*) as 总数量, sum(case when level='一级' then 1 else 0 end) as 一级, sum(case when level='二级' then 1 else 0 end) as 二级, sum(case when level='三级' then 1 else 0 end) as 三级 from table group by type
--高级查询在数据库中用得是最频繁的,也是应用最广泛的。 Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 select distinct sex from student; --count 统计 select count(*) from student; select count(sex) from student; select count(dis
通常情况下我们写sql语句主键都是唯一的不会出现id重复的问题。如:
查询表table1的所有数据
select * from table1
会显示出table1中所有字段列表。
select count(*) as count from table1
统计table表中数据总数也不会有问题。
但是如果使用的分组group by那么问题就会出现统计不准的问题
select count(*) from table1 where status=1
返回结果
但是如果这样写就会按分组统计总数,不是我