• 博客访问： 1398706
• 博文数量： 309
• 博客积分： 1966
• 博客等级： 上尉
• 技术积分： 2665
• 用 户 组： 普通用户
• 注册时间： 2011-12-08 16:19

Follow excellent,And success will chase you.

2012-11-06 14:38:54

count()函数即根据给定的范围和group by(统计方式) 而统计行数据的条数

1. select s e x from student (查询数据表中的存在的男女条数)

2.select s e x, count (*) as num from student group by s e x (查询表中男女数量)

3.select s e x ,province, count (*)as num from student group by s e x,province (查询各省男女数量)

4.select s e x ,province, count (province)as num from student group by s e x,province (查询各省男女数量)

5.select s e x ,province, count ( case province when '浙江省' then '浙江省' end )as num from student group by s e x,province

6.select s e x, count ( case province when '浙江省' then '浙江省' end ) as 浙江省 from student group by s e x

7.select s e x ,count ( case province when '广东省' then '广东省' end )as 广东省 ,count ( case province when '江西省' then '江西省' end )as 江西省 ,count ( case province when '浙江省' then '浙江省' end )as 浙江省 from student group by s e x

(1) select (case province when '浙江省' then '浙江' when '江西省' then '江西' end ) as 省份 from student

(2)select (case province when '浙江省' then '浙江' when '江西省' then '江西' else province end ) as 省份 from student

(3)ACCESS中并无case...when...then的结构，但有IIF函数可以实现同样的功能。

*注：本文转自