sql中case when then简单用法
2013-10-03 14:24
633 查看
如想统计一栋楼里边各学历的分布情况,即各学历有多少人,degree是学历。下图为数据库:
①普通的写法是
结果为:
②但若要求得到学历的详细信息,上图就显得不那么直观。可以使用case when then end写法来转化数据库中的信息。
结果为:
这样效果会更好些。
①普通的写法是
select degree, count(degree) dnum from t_resident where build_id=1 group by degree;
结果为:
②但若要求得到学历的详细信息,上图就显得不那么直观。可以使用case when then end写法来转化数据库中的信息。
select ( case when degree=1 then '高中以下' when degree=2 then '高中' when degree=3 then '大专' when degree=4 then '本科' when degree=5 then '硕士' when degree=6 then '博士' else '博士以上' end )lable,degree, count(degree) dnum from t_resident where build_id=1 group by degree;
结果为:
这样效果会更好些。
相关文章推荐
- SQL case when then end 简单用法
- sql case when 简单用法
- sql中case when then的用法
- sql语句中"case when"的简单用法示例
- SQL中的case when then else end用法
- SQL中的case when then else end用法
- case...when...简单用法sql说明
- SQL中CASE WHEN THEN的用法
- SQL中case when then用法
- sql case when then end 用法
- SQL条件控制(case when...then...else...end)用法描述
- SQL中的case when then else end用法
- SQL中的case when then else end用法
- SQL的case when then else end语句的用法
- Oracle case when then简单用法
- SQL中的case when then else end详细用法
- SQL中的case when then else end用法
- SQL中的case when then else end用法
- SQL中的case when then else end用法
- case when then...else end sql 语句用法