当前位置:网站首页>MySQL row column conversion (updated version)
MySQL row column conversion (updated version)
2022-06-13 07:22:00 【Dongbei bird】
Recommended if The sentence of :
if( Want to become the column name of the row = ‘ The value of the column ’, Another column name ) ‘ Alias this field ’
Create table statement
create table test (Date varchar(10), item char(10),saleqty int);
insert test values('2010-01-01','AAA',8);
insert test values('2010-01-02','AAA',4);
insert test values('2010-01-03','AAA',5);
insert test values('2010-01-01','BBB',1);
insert test values('2010-01-02','CCC',2);
insert test values('2010-01-03','DDD',6);

SELECT * ,
case item when 'AAA' THEN saleqty ELSE 0 end as A,
case item when 'BBB' THEN saleqty ELSE 0 end as B,
case item when 'CCC' THEN saleqty ELSE 0 end as C
FROM TEST

select *,
if(item = 'AAA',saleqty,0) 'A',
if(item = 'BBB',saleqty,0) 'B',
if(item = 'CCC',saleqty,0) 'C'
FROM TEST

select *,
max(if(item = 'AAA',saleqty,0)) 'A',
max(if(item = 'BBB',saleqty,0) )'B',
max(if(item = 'CCC',saleqty,0) )'C'
FROM TEST

边栏推荐
- RT thread simulator lvgl control: slider control
- 论文笔记: 多标签学习 BP-MLL
- redis-3. Redis list, set, hash, sorted_ set、skiplist
- RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
- P1434 [SHOI2002] 滑雪 (记忆化搜索
- 全志V3S环境编译开发流程
- 10 Honest Facts I Want To Share With All Junior Developers
- Interview questions must be asked - Optimization of large table Pagination
- SDN basic overview
- C Advanced Programming - features
猜你喜欢

Department store center supply chain management system

C # related knowledge points

Real time lighting of websocket server based on esp32cam

RT thread simulator lvgl control: slider control

RT thread simulator lvgl control: button button event

RT thread simulator lvgl control: button button style

Implementation of fruit mall wholesale platform based on SSM

Simple understanding of basic language of C language

Mui mixed development - when updating the download app, the system status bar displays the download progress

Try to use renderdoc to view the shader code of UE
随机推荐
Lightning breakpoint continuation
About database: pgadmin4 editing SQL window
Try to use renderdoc to view the shader code of UE
P6154 游走(记忆化搜索
How idea breaks point debugging
Is it safe for Hangzhou Securities to open an account?
Mui mixed development - when updating the download app, the system status bar displays the download progress
redis-3. Redis list, set, hash, sorted_ set、skiplist
I always don't understand the high address and high position
c#高級編程-特性篇
Quick sort
B. I Hate 1111 (记忆化搜索 数论
Local file upload FTP or remote directory
领先企业的管理实践证明,企业可持续发展的核心是什么?
Why should two judgment expressions in if be written in two lines
Personal JS learning notes
[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution
RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
汇编语言基础:寄存器和寻址方式
百货中心供应链管理系统