LeetCode 1278. 分割回文串 III(區間DP)
阿新 • • 發佈:2020-12-30
今天無聊去看部落格問答,看見了行轉列的問題,就動手解決下,牢固牢固
自己建的示例表如下
sql如下
這裡用到ifnull函式把為空的值程式設計0,寫的不好勿噴哈哈哈哈
SELECT DISTINCT c.name,
IFNULL((SELECT COALESCE(1,null) FROM b WHERE tab = 1 and name = c.name ) ,0)AS '早餐' ,
IFNULL((SELECT COALESCE(1,null) FROM b WHERE tab = 2 and name = c.name ),0) AS '中餐' ,
IFNULL((SELECT COALESCE(1,null) FROM b WHERE tab = 3 and name = c.name ) ,0) AS '晚餐'
FROM b c
結果如下