1、中软国际 SQL行转列

 变成  

--数据准备
create table t_test(
year int,
month int,
sale int,
primary key (year, month)
); insert into t_test values (1991, 1, 110);
insert into t_test values (1991, 2, 120);
insert into t_test values (1991, 3, 130);
insert into t_test values (1991, 4, 140);
insert into t_test values (1992, 1, 210);
insert into t_test values (1992, 2, 220);
insert into t_test values (1992, 3, 230);
insert into t_test values (1992, 4, 240);
select year as '年份',
max(case month when 1 then sale else 0 end) as '一月',
max(case month when 2 then sale else 0 end) as '二月',
max(case month when 3 then sale else 0 end) as '三月',
max(case month when 4 then sale else 0 end) as '四月',
max(case month when 5 then sale else 0 end) as '五月'
from t_test group by year;

二、东方通达 复杂查询

--标准版
SELECT a.class, AVG(score), COUNT(username) FROM
(SELECT class, avg(score) FROM table1 LEFT JOIN table2
ON table1.username = table2.username GROUP BY class) AS a
     LEFT JOIN
   (SELECT class, COUNT(username) FROM table1 LEFT JOIN table2
ON table1.username = table2.username WHERE score < 60 GROUP BY class) AS c
ON a.class = c.class; --变态版
select class, avg(score), sum(if(score < 60, 1, 0))
 from table1 left join table2  ON  table1.username = table2.username  GROUP BY  class

最新文章

  1. golang sync.WaitGroup bug
  2. 『.NET Core CLI工具文档』(十一)dotnet-test
  3. mysql小数格式化正确方法
  4. Oracle创建数据库
  5. android 学习第一天 了解事件机制,页面跳转等常用操作
  6. WDR7500 花生壳问题
  7. MFC 配合 protobuff libevent 实现的Socket 的GM工具 框架
  8. maven pom.xml报错
  9. 简单聊下Unicode和UTF-8
  10. (转)linux中fork()函数详解
  11. Atan2
  12. poj3259
  13. 在一个exe文件中查找指定内容,找到则返回起始位置, 否则返回0
  14. mock server相关解决方案
  15. 聊聊Node.js 独立日漏洞
  16. 复杂SQL代码实例
  17. 读Zepto源码之Ajax模块
  18. 用ECMAScript4 ( ActionScript3) 实现Unity的热更新 -- CustomYieldInstruction 自定义中断指令
  19. c#面试题汇总(1)
  20. C++实现串口的自动识别

热门文章

  1. 概率dp——hdu4089推公式+循环迭代
  2. react 组件的生命周期 超简版
  3. 实时检测网络状态及是否可以连接Internet
  4. 关于python3字符串中引号格式的看法,‘’,“”
  5. 02.万恶之源-python 运算符和编码
  6. 用户管理模块之mysql.user
  7. 2、docker镜像管理
  8. MQTT入门介绍
  9. loj6005 [网络流24题]最长递增子序列
  10. SpringBoot_Mybatis MyBatisPlus