mysql case when 根据数字排序 返回 string类型问题

这个问题研究了一上午

原因:查询的拜访得分不是这个拜访人
解决方案:使用cancat_ws()拼接拜访得分和拜访人,得分在前,根据得分自动排序
select
MAX(case when t.WorkDate='2020-01-13' then t.PersonName else Null end) as Temp1, -- 拜访人1
substring_index(MAX(case when t.WorkDate='2020-01-13' then concat_ws('_',t.FactScore,t.PersonName) else Null end),'_',-1) as Temp2, -- 拜访人2
MAX(case when t.WorkDate='2020-01-13' then t.FactScore else Null end) as Temp3 -- 拜访得分3
from test t;

猜你喜欢

转载自www.cnblogs.com/Jhon-xu/p/12214545.html