MySQL查询格式化时间戳及case then使用

FROM_UNIXTIME(created_at,'%Y-%m-%d %H:%i:%S') as payTimeStr

%W 星期名字(Sunday……Saturday)
%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)
%Y 年, 数字, 4 位
%y 年, 数字, 2 位
%a 缩写的星期名字(Sun……Sat)
%d 月份中的天数, 数字(00……31)
%e 月份中的天数, 数字(0……31)
%m 月, 数字(01……12)
%c 月, 数字(1……12)
%b 缩写的月份名字(Jan……Dec)
%j 一年中的天数(001……366)
%H 小时(00……23)
%k 小时(0……23)
%h 小时(01……12)
%I 小时(01……12)
%l 小时(1……12)
%i 分钟, 数字(00……59)
%r 时间,12 小时(hh:mm:ss [AP]M)
%T 时间,24 小时(hh:mm:ss)
%S 秒(00……59)
%s 秒(00……59)
%p AM或PM
%w 一个星期中的天数(0=Sunday ……6=Saturday )
%U 星期(0……52), 这里星期天是星期的第一天
%u 星期(0……52), 这里星期一是星期的第一天
%% 一个文字“%”。

##case then

#测试任务表
select '测试任务编号' as id,'测试项目名称' as name,'测试领域' as test_area,'测试经理' as creator_id,'测试项目简介' as summary,'测试状态' as status,'来函测试类型' as type,'牵头部所' as lead_dept,'参与部所' as assist_depts,'管理经理' as manager_id,'测试执行开始时间' as execute_real_start_time,'启动会时间' as start_meeting_time
union all
select id,name,test_area,creator_id,summary,case status when 10 then '启动' when 20 then '准备' when 30 then '执行' when 40 then '总结' when 99 then '结束' when 100 then '终止' end as status,case type when 1 then '集采' when 2 then '入网' when 3 then '其它采购类测试' when 4 then '部件替换测试' end as type,lead_dept,assist_depts,manager_id,FROM_UNIXTIME(execute_real_start_time,'%Y-%m-%d %H:%i:%S') as execute_real_start_time,FROM_UNIXTIME(start_meeting_time,'%Y-%m-%d %H:%i:%S') as start_meeting_time from tms_task where del_flg=0 and created_at > 1640966400

#统计订单sum(case  then)使用

 

select sum(case when pay_status=1 then price else 0 end) as total_price from sxo_order

select count(case when pay_status=1 then 1 end) as valid_count from sxo_order

posted @ 2022-10-09 14:25  技艺追求者  阅读(521)  评论(0)    收藏  举报