leetcode-Database-1777 |每家商店的产品价格

原题

在这里插入图片描述

分析

行转列

代码

代码实现-case when

select product_id,
SUM(case store when 'store1 ' then price  ELSE null end) as store1 ,
SUM(case store when 'store2 ' then price  ELSE null end) as store2 ,
SUM(case store when 'store3 ' then price  ELSE null end) as store3 
from Products 
group by product_id

猜你喜欢

转载自blog.csdn.net/qq_38173650/article/details/114694187