create table capacity(

typeint,

numbersint,

monthst INT

);

select type,

sum(case monthst when 1 then numbers else 0 end ) 一月,

sum(case monthst when 2 then numbers else 0 end ) 二月,

sum(case monthst when 3 then numbers else 0 end ) 三月,

sum(case monthst when 4 then numbers else 0 end ) 四月,

sum(case monthst when 5 then numbers else 0 end ) 五月,

sum(case monthst when 6 then numbers else 0 end ) 六月,

sum(case monthst when 7 then numbers else 0 end ) 七月,

sum(case monthst when 8 then numbers else 0 end ) 八月,

sum(case monthst when 9 then numbers else 0 end ) 九月,

sum(case monthst when 10 then numbers else 0 end ) 十月,

sum(case monthst when 11 then numbers else 0 end ) 十一月,

sum(case monthst when 12 then numbers else 0 end ) 十二月

from capacity group by type;

按type分组,并对每月的对应type的numbers求和。

select cap.type,sum(cap.a+cap.b+cap.c) 一季度,sum(cap.d+cap.e+cap.f) 二季度,sum(cap.g+cap.h+cap.i) 三季度,sum(cap.j+cap.k+cap.l) 四季度 from

(select type,

sum(case monthst when 1 then numbers else 0end ) a,

sum(case monthst when 2 then numbers else 0end ) b,

sum(case monthst when 3 then numbers else 0end ) c,

sum(case monthst when 4 then numbers else 0end ) d,

sum(case monthst when 5 then numbers else 0end ) e,

sum(case monthst when 6 then numbers else 0end ) f,

sum(case monthst when 7 then numbers else 0end ) g,

sum(case monthst when 8 then numbers else 0end ) h,

sum(case monthst when 9 then numbers else 0end ) i,

sum(case monthst when 10 then numbers else 0end ) j,

sum(case monthst when 11 then numbers else 0end ) k,

sum(case monthst when 12 then numbers else 0end ) l

from capacity group by type) cap

group by cap.type;

再对每行多列合并求和。

mysql 行转列 显示_mysql 行转列 (结果集以坐标显示)相关推荐

  1. mysql行转列和列转行_Mysql中行转列和列转行

    一.行转列 即将原本同一列下多行的不同内容作为多个字段,输出对应内容. 建表语句 DROP TABLE IF EXISTS tb_score; CREATE TABLE tb_score( id IN ...

  2. MySQL 行之间连接符_MySQL行转列 列转行 连接字符串 潍鲸 潍鲸科技

    创建MySQL数据库表结构 DROP TABLE IF EXISTS `weijing`; CREATE TABLE `weijing` ( `Id` int(11) NOT NULL AUTO_IN ...

  3. mysql多列索引_MySQL的多列索引

    什么是索引? 索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表里面 ...

  4. mysql 删除字段的注释_MySQL表和列的注释总结

    像代码一样,可以为表以及表中的列添加注释,方便其他人知晓其功能.对于一些字段,在经过一定时间后,创建者未必也能想起其具体的含意,所以注释显得尤为重要. 注释的添加 注释的添加是通过在定义表或列的时候在 ...

  5. mysql php 列转行_MySql行转列、列转行

    现mysql中有一张表php_user表,表结构为: 表中数据有: 现在想查询出来不同学生的语数外成绩在一行显示,那么需要用到行转列的用法, 一.行转列 1.使用case...when....then ...

  6. mysql行转列和列转行_mysql 行转列和列转行实例详解

    mysql行转列.列转行 语句不难,不做多余解释了,看语句时,从内往外一句一句剖析 行转列 有如图所示的表,现在希望查询的结果将行转成列 建表语句如下: create table `test_tb_g ...

  7. mysql 行转列 (结果集以坐标显示)

    create table capacity(type int ,numbers int ,monthst INT ); select type, sum(case monthst when 1 the ...

  8. mysql 行级锁 索引_mysql 行级锁 索引唯一值

    做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统.假设 id=1 的这本书库存为 1 ,但是有 2 个人同时来借这本书,此处的逻辑为 Select rest ...

  9. mysql 创建分区索引吗_MySQL分区字段列有必要再单独建索引吗?

    大家都知道对于分区字段必须是主键的一部分,那么建了复合主键之后,是否需要对分许字段再单独添加一个索引呢?有没有效果?本文主要给大家介绍了关于MySQL分区字段列是否有必要再单独建索引的相关资料,文中通 ...

最新文章

  1. Docker命令基础 简洁版本
  2. android PreferenceActivity详解
  3. 如何优雅地处理 EF Core 异常
  4. Java StringBuffer 方法
  5. 带有Spring,Hibernate,Akka,Twitter Bootstrap,Apache Tiles和jQuery的Maven Web项目Kickstarter代码库...
  6. 7-121 深入虎穴 (25 分)(dfs,bfs)
  7. POJ C++程序设计 编程题#2 魔兽世界之二:装备
  8. oracle的磁盘测试工具orion
  9. Python 函数知识
  10. 美国数学家维纳智力早熟,11岁就上了大学,他曾在1935-1936年 应邀参加中国清华大学讲学,一次他参加某个重要会议,年轻的脸孔 引人注意,于是有人询问他的年龄,他回答说“我年龄的立方是个4位数
  11. 软件测试之黑盒测试白盒测试
  12. Hyperspace初体验:Delta Lake表索引
  13. 什么是服务器?服务器是用来做什么的?
  14. 华为鸿蒙未来生态,华为王成录:鸿蒙生态构建成功后,未来移动产业20年将属于中国...
  15. ESP8266_遥控小车网页版
  16. (亲测可用)如何在Win10家庭版中找回组策略编辑器
  17. java递归获取树结构的指定层级、指定层级之上(向上递归(包含父集所有、爷爷集所有...)(父集单独、爷爷集单独...))、指定层级之下所有的(子集、孙子集...)和list集合转Tree树结构
  18. Markdown还能这么玩?这款开源神器绝了
  19. python count函数用法示例_python count函数用法详解
  20. [学习] 09 一小时读100页的快速阅读法

热门文章

  1. 【报告分享】2021中国人才趋势报告.pdf(附下载链接)
  2. 【报告分享】德勤-教育行业发展报告(政策、资本、AI、职业教育).pdf2019年中国外卖产业调查研究报告.pdf...
  3. mips指令分类和寻址大全
  4. 深度融合 | 当推荐系统遇见知识图谱(三)
  5. 关于不过洋节的通知_国家有规定不许过圣诞节等洋节吗?
  6. python获取调用函数的注释,如何使用函数注释验证函数调用类型
  7. 读书笔记——数据压缩入门(柯尔特·麦克安利斯)上
  8. 吴恩达《机器学习》第十三章:聚类
  9. 吴恩达机器学习 5.正则化
  10. Linux编程(9)_进程