博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

MySQL SQL题

1 列转行

 

select 
lcase(`name`) as `name`,
sum(CASE TYPE when 'Breakfast' THEN `VALUE` else 0 end) as Breakfast,
sum(CASE TYPE when 'Lunch' THEN `VALUE` else 0 end) as Lunch,
sum(CASE TYPE when 'Supper' THEN `VALUE` else 0 end) as Super
from cust_value group by `name`

 

posted @ 2023-02-14 20:10  CHANG_09  阅读(14)  评论(0编辑  收藏  举报