Mysql 列轉行 例項

2021-10-18 22:40:00 字數 1892 閱讀 5082

**箱表

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 comment '活動下的箱子編號',

primary key (`id`)

) engine=innodb auto_increment=112 default charset=utf8 comment='**箱表';

**箱-獎品-中間表

create table `yoshop_shang_box_goods` (

`id` int(11) not null auto_increment comment '編號',

`box_id` int(11) not null comment '**箱id',

`category_id` int(11) not null comment '商品分類id',

`goods_id` int(11) not null comment '商品id',

`total` int(11) not null comment '對應商品在**箱內的總數',

`stock_num` int(11) not null comment '對應商品在**箱內的餘數',

primary key (`id`)

) engine=innodb auto_increment=332 default charset=utf8 comment='**箱-獎品-中間表';

mysql行轉列 列轉行 含例項

1.行轉列 有如圖所示的表,現在希望查詢的結果將行轉成列 語文,數學,英文變成列 使用如下查詢語句實現行轉列 select id,name,max case when course 語文 then score else 0 end 語文 max case when course 數學 then sc...

列轉行的Oracle SQL例項

select t.eles t.sendunit name,t.rom seqno,ltrim max sys connect by path t.model,model from select eles sendunit name,rom seqno,model,min model over pa...

Mysql 採用列轉行

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