1、统计行数,转成列显示。
CREATE TABLE `shop_20231223` (`name_ed` varchar(255) DEFAULT NULL,`time_ed` varchar(255) DEFAULT NULL,`day_ed` int DEFAULT NULL
) select
sum(case when day_ed ='9' then 1 else 0 end) month_9,
sum(case when day_ed ='10' then 1 else 0 end) month_10,
sum(case when day_ed ='11' then 1 else 0 end) month_11,
sum(case when day_ed ='12' then 1 else 0 end) month_12
from shop_20231223 s2;
1.1、可以把上面的 1 变成,表中的某个字段(求和),代码如下:
select
sum(case when day_ed ='9' then num_ed else 0 end) month_9,
sum(case when day_ed ='10' then num_ed else 0 end) month_10,
sum(case when day_ed ='11' then num_ed else 0 end) month_11,
sum(case when day_ed ='12' then num_ed else 0 end) month_12
from shop_20231223 s2;
2、添加自动,删除字段,修改字段属性(如更改字段长度)
3、
4、
5、
6、
7、
8、
9、