大劍無鋒之mysql列轉行 面試推薦

2021-10-01 09:55:39 字數 938 閱讀 8757

還是一句sql轉化!!!

還沒想好怎麼寫。。。

在第一題中

第二題就是我上面所說的,我想不出來,不過使用hive的sql可以進行操作。

select sc.name, split(sc.course_grade, ':')[0] as course, sg.grade from student_course 

sc left join (select t1.name, grade from (select name, split(grades, ',') as grades from

student_grades) t1

lateral view explode(grades) tmp as grade) sg on sc.name = sg.name and

split(sc.course_grade, ':')[1]=sg.grade;

可以實現。

不過我又問一些朋友他們說這道題可能是a轉c。。

這樣的話。比較好解決。

Mysql 列轉行 例項

箱表 create table yoshop shang activity box id int 11 not null auto increment comment 編號 activity id int 11 not null comment 活動id number int 11 not null...

Mysql 採用列轉行

欄位的拆分 使用函式substring index str,delim,count str 拆分物件 delim 拆分標識 substring index 搜尋時執行區分大小寫的匹配 delim count 拆分方式 如果 count為正,則返回最終分隔符左側的所有內容 從左側開始計算 如果coun...

mysql 列轉行,合併字段

列轉行 利用max case when then max 聚合函式 取最大值 casecoursewhen 語文 thenscoreelse0end 判斷 as 語文 別名作為列名 select name max case when course 語文 then score end as語文,max...