[데이터 베이스]16.piot

손영민's avatar
Mar 09, 2025
[데이터 베이스]16.piot
행의 값을 열로 변환하는것
 
notion image
 
 
-- 값을 컬럼으로 변환 select * from cal; select sum(if(day='일',num_day,0)) '일', sum(if(day='월',num_day,0)) '월', sum(if(day='화',num_day,0)) '화', sum(if(day='수',num_day,0)) '수', sum(if(day='목',num_day,0)) '목', sum(if(day='금',num_day,0)) '금', sum(if(day='토',num_day,0)) '토' from cal where week = 1; select week, sum(if(day='일',num_day,0)) '일', sum(if(day='월',num_day,0)) '월', sum(if(day='화',num_day,0)) '화', sum(if(day='수',num_day,0)) '수', sum(if(day='목',num_day,0)) '목', sum(if(day='금',num_day,0)) '금', sum(if(day='토',num_day,0)) '토' from cal group by week; create table cal2 as select day, num_day from cal; select * from cal2;
 
 
notion image
 
1 7= ceil(0.x) 1 2 7= ceil(0.x) 1 3 7= ceil(0.x) 1 4 7= ceil(0.x) 1 5 7= ceil(0.x) 1 6 7= ceil(0.x) 1 7 7= ceil(0.x) 2 8 7= ceil(0.x) 2 9 7= ceil(0.x) 2 10 7= ceil(0.x) 2 11 7= ceil(0.x) 2 12 7= ceil(0.x) 2 13 7= ceil(0.x) 2 14 7= ceil(0.x) 2 15 7= ceil(0.x) 3
Share article

sson17