Mysql 採用列轉行

2021-10-23 07:37:15 字數 1883 閱讀 4717

欄位的拆分:使用函式substring_index(str,delim,count)

str:拆分物件

delim:拆分標識、substring_index()搜尋時執行區分大小寫的匹配 delim

count:拆分方式:如果 count為正,則返回最終分隔符左側的所有內容(從左側開始計算)。如果count是否定的,則返回最終分隔符右側的所有內容(從右側開始計算)。

使用substring_index實現列轉行的效果,需要使用第三方序列標識,進行分行。在mysql中,可以使用help_topic的help_topic_id。 當然,其實使用 任意乙個 可以自增的字段 都可以的,比如建立表中有乙個自增的主鍵id,用這個字段……

參考:

select

group_concat()會計算哪些行屬於同一組,將屬於同一組的列顯示出來。要返回哪些列,由函式引數(就是欄位名)決定。分組必須有個標準,就是根據group by指定的列進行分組。

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 列轉行,合併字段

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

Mysql 行轉列 列轉行

create table test tb grade id int 10 not null auto increment,user name varchar 20 default null,course varchar 20 default null,score float default 0 pr...