当前位置:网站首页>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
边栏推荐
- 量化框架backtrader之一文读懂Analyzer分析器
- Oracle problem: the data in the field is separated by commas. Take the data on both sides of the comma
- Micro isolation (MSG)
- About database: pgadmin4 editing SQL window
- It's called the next generation monitoring system. Let's see how awesome it is
- redis-4. Redis' message subscription, pipeline, transaction, modules, bloom filter, and cache LRU
- NFV基本概述
- redis-3. Redis list, set, hash, sorted_ set、skiplist
- Tree list under winfrom treelist related
- P6154 wandering (memory search
猜你喜欢
TiDB Lightning
redis-1. Install redis with pictures and texts
Tree list under winfrom treelist related
微隔离(MSG)
How worker threads in the thread pool are recycled
[Markov chain Monte Carlo] Markov chain Monte Carlo method sampling prior distribution
One article of quantitative framework backtrader read analyzer
Application of DS18B20 temperature sensor based on FPGA
redis-3. Redis list, set, hash, sorted_ set、skiplist
How to write an amazing design document?
随机推荐
I always don't understand the high address and high position
A. Vacations (DP greed
Nfv basic overview
Local file upload FTP or remote directory
Personal JS learning notes
How to use clion to debug a project built by the make tool
redis-3. Redis list, set, hash, sorted_ set、skiplist
SDN basic overview
不同系统添加证书
The password does not take effect after redis is set
What does my financial product mean in clearing?
. Net code to implement get request and post request
Lightning breakpoint continuation
NFV基本概述
考研英语
Real time lighting of websocket server based on esp32cam
Socket programming 2:io reuse (select & poll & epoll)
Problems encountered during commissioning of C # project
C # related knowledge points
How to stop PHP FPM service in php7