mysql我所遇到的问题case when then的使用
来源:互联网 发布:算法竞赛入门经典 白书 编辑:程序博客网 时间:2024/06/16 15:12
在项目中出的问题总结方便以后自己查看也希望能帮到遇到类似问题的朋友,最近项目中有个需求就是省级用户查看申请时候,如果是县级用户申请的要把县级用户合并的市级用户中,如果是市级用户只需要统计就行。已知市级用户开头的四位数字。
select
CASE
WHEN substring(ptgw.xzqh,1,4) = '3301' THEN '杭州'
WHEN substring(ptgw.xzqh,1,4) = '3303' THEN '温州'
WHEN substring(ptgw.xzqh,1,4) = '3304' THEN '嘉兴'
WHEN substring(ptgw.xzqh,1,4) = '3305' THEN '湖州'
WHEN substring(ptgw.xzqh,1,4) = '3306' THEN '绍兴'
WHEN substring(ptgw.xzqh,1,4) = '3307' THEN '金华'
WHEN substring(ptgw.xzqh,1,4) = '3308' THEN '衢州'
WHEN substring(ptgw.xzqh,1,4) = '3309' THEN '舟山'
WHEN substring(ptgw.xzqh,1,4) = '3310' THEN '台州'
WHEN substring(ptgw.xzqh,1,4) = '3311' THEN '丽水' END as sxmc,
CASE
WHEN substring(ptgw.xzqh,1,4) = '3301' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3301'))
WHEN substring(ptgw.xzqh,1,4) = '3303' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3303'))
WHEN substring(ptgw.xzqh,1,4) = '3304' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3304'))
WHEN substring(ptgw.xzqh,1,4) = '3305' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3305'))
WHEN substring(ptgw.xzqh,1,4) = '3306' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3306'))
WHEN substring(ptgw.xzqh,1,4) = '3307' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3307'))
WHEN substring(ptgw.xzqh,1,4) = '3308' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3308'))
WHEN substring(ptgw.xzqh,1,4) = '3309' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3309'))
WHEN substring(ptgw.xzqh,1,4) = '3310' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3310'))
WHEN substring(ptgw.xzqh,1,4) = '3311' THEN (select count(*) from fm_ws_ptgw_jd where zt in(0,-1,-2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3311')) END as undeclareCounts,
CASE
WHEN substring(ptgw.xzqh,1,4) = '3301' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3301'))
WHEN substring(ptgw.xzqh,1,4) = '3303' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3303'))
WHEN substring(ptgw.xzqh,1,4) = '3304' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3304'))
WHEN substring(ptgw.xzqh,1,4) = '3305' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3305'))
WHEN substring(ptgw.xzqh,1,4) = '3306' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3306'))
WHEN substring(ptgw.xzqh,1,4) = '3307' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3307'))
WHEN substring(ptgw.xzqh,1,4) = '3308' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3308'))
WHEN substring(ptgw.xzqh,1,4) = '3309' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3309'))
WHEN substring(ptgw.xzqh,1,4) = '3310' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3310'))
WHEN substring(ptgw.xzqh,1,4) = '3311' THEN (select count(*) from fm_ws_ptgw_jd where zt in(1,2) and nd=2017 and yf=6 and substring(fm_ws_ptgw_jd.xzqh,1,4) LIKE CONCAT ('3311')) END as alreadydeclareCounts
from fm_ws_ptgw_jd ptgw
group by substring(ptgw.xzqh,1,4)
数据库表的数据:
查询结果:
- mysql我所遇到的问题case when then的使用
- mysql中case when then 的使用
- 【DB】MySQL中case when then 的使用
- mysql数据库中case...when...then...end语句的使用
- 急CASE.WHEN.THEN.中使用别名的有关问题
- case when then else end 的使用
- Case when ....then的用法
- case when then的用法
- case when then的用法
- CASE WHEN THEN的使用方法
- MYSQL--case...when...then
- MySQL CASE WHEN THEN
- mysql case when then end使用方式
- mysql的case when then else end语法的例子。
- mysql中的case when then,replace的用法。
- mysql中case-when-then和oracle的decode函数
- mysql中case、when、if、then的用法
- MySql 中 case when then else end 的用法
- CSS小功能
- 学习linux内核(二)
- 常用正则表达式
- Powershell命令笔记
- oracle 序列和触发器的联合使用
- mysql我所遇到的问题case when then的使用
- 常见浏览器兼容性
- 10-S3C2440驱动学习(六)嵌入式linux-触摸屏设备驱动
- String的subString()和toUpCase()用法
- MyBatis学习笔记
- 远程登录工具 —— filezilla(FTP vs. SFTP)、xshell、secureCRT
- 常用sql
- 关于常见的几种缓存算法
- jQuery