MySQL 字段值归类重命名,并自定义排序,使用 case when in() then

1、mysql自定义排序,指定排序输出:

SELECT 
CASE WHEN ajj_whcd="" then "未知"
     WHEN ajj_whcd IN ("初中", "中学") THEN "初中"
     WHEN ajj_whcd IN ("中专","中技","中专(中技)", "中师","技工","技校","普高","职专","职中", "高中","高中?") THEN "高中"
     WHEN ajj_whcd IN ("专科", "大专", "大专?", "职高", "大专毕业", "高技", "高职") THEN "大专"
     WHEN ajj_whcd IN ("本科","本科?","学士", "理科","函授本科", "大学","大学本科") THEN "本科"
     ELSE "研究生" END AS whcd, count(ajj_sfzh)
FROM yw_ajj_saqscjdglj_aqscr 
GROUP BY whcd
order by field(whcd,"初中","高中", "大专","本科","研究生","未知")


2、加序号

select @rows:=@rows + 1 as rows,pname,sex,jobtype,education
from tsafe_pxrecords_kpi,(select @rows := 0) r
where str_to_date(concat(certi_end_year,'-',certi_end_month,'-',certi_end_day),'%Y-%m-%d')>=DATE_FORMAT(now(),'%Y-%m-%d')

————————————————
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值