从MySQL字段中分隔几天

时间:2017-01-29 06:07:08

标签: mysql sql

美好的一天,我遇到了一个问题,其中天数的值用MTWThF,ThF,TTh等格式化。我想转换成列。这是我的代码:

SELECT 
dys,
CASE WHEN dys LIKE 'M%' THEN 'M' ELSE '' END AS M,
CASE WHEN (dys LIKE '%T%' AND NOT '%Th%') THEN 'T' ELSE '' END AS T,
CASE WHEN dys LIKE '%W%' THEN 'W' ELSE '' END AS W,
CASE WHEN dys LIKE '%Th%' AND NOT 'T' THEN 'Th' ELSE '' END AS th,
CASE WHEN dys LIKE '%F%' THEN 'F' ELSE '' END AS F,
CASE WHEN (dys LIKE '%S%' AND NOT 'Su') THEN 'S' ELSE '' END AS S,
CASE WHEN (dys LIKE '%Su%' AND NOT 'S') THEN 'Su' ELSE '' END AS Su
FROM sched
GROUP BY dys

,结果是

Tb result

直到在来自SSu的ThF相同的S上检测到T.我错过了什么吗?谢谢

0 个答案:

没有答案