行转列 ,转不出来啊!

img


行转列转不出来,转出来是空的,但要求变成字符null实在不懂了

行转列,列传行可参考:https://blog.csdn.net/jungeCSND/article/details/101060085?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165588158416782425183964%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165588158416782425183964&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-101060085-null-null.nonecase&utm_term=%E8%A1%8C%E8%BD%AC%E5%88%97&spm=1018.2226.3001.4450

select
lower(name) name,
max(case when Type='Breakfast' then value end)"Breakfast",
max(case when Type='Lunch'and name='Lisi' then 'null' when Type='Lunch' then value end)"Lunch",
max(case when Type='Dinner' then value end)"Dinner"
from cs
group by name

img

题里写的null,只是为了告诉你这里是空,不是想让你在这里显示null的字符串,因为这里不填点什么东西的话,可能和空格或者TAB符有歧义