先根据以下代码来创建表MonthlyOrders并导入一定的数据

CREATE TABLE MonthlyOrders(
ordermonth DATE,
ordernum INT UNSIGNED,
PRIMARY KEY (ordermonth)
);
INSERT INTO MonthlyOrders SELECT '2010-02-01',23;
INSERT INTO MonthlyOrders SELECT '2010-03-01',26;
INSERT INTO MonthlyOrders SELECT '2010-04-01',24;
INSERT INTO MonthlyOrders SELECT '2010-05-01',27;
INSERT INTO MonthlyOrders SELECT '2010-06-01',26;
INSERT INTO MonthlyOrders SELECT '2010-07-01',32;
INSERT INTO MonthlyOrders SELECT '2010-08-01',34;
INSERT INTO MonthlyOrders SELECT '2010-09-01',30;
INSERT INTO MonthlyOrders SELECT '2010-10-01',31;
INSERT INTO MonthlyOrders SELECT '2010-11-01',32;
INSERT INTO MonthlyOrders SELECT '2010-12-01',33;
INSERT INTO MonthlyOrders SELECT '2011-01-01',31;
INSERT INTO MonthlyOrders SELECT '2011-02-01',34;
INSERT INTO MonthlyOrders SELECT '2011-03-01',34;
INSERT INTO MonthlyOrders SELECT '2011-04-01',38;
INSERT INTO MonthlyOrders SELECT '2011-05-01',39;
INSERT INTO MonthlyOrders SELECT '2011-06-01',35;
INSERT INTO MonthlyOrders SELECT '2011-07-01',49;
INSERT INTO MonthlyOrders SELECT '2011-08-01',56;
INSERT INTO MonthlyOrders SELECT '2011-09-01',55;
INSERT INTO MonthlyOrders SELECT '2011-10-01',74;
INSERT INTO MonthlyOrders SELECT '2011-11-01',75;
INSERT INTO MonthlyOrders SELECT '2011-12-01',14;
滑动订单问题是指为每个月返回上一年度(季度或月度)的滑动订单数,即每个月份N,返回N-11到月份N的订单总数。这里,假设月份序列中不存在间断。
执行下面的SQL查询实现每个月返回上一年度的滑动订单总数

SELECT
DATE_FORMAT(a.ordermonth, '%Y%m') AS frommonth,
DATE_FORMAT(b.ordermonth, '%Y%m') AS tomonth,
SUM(c.ordernum) AS orders
FROM monthlyorders a
INNER JOIN monthlyorders b
ON DATE_ADD(a.ordermonth, INTERVAL 11 MONTH) = b.ordermonth
INNER JOIN monthlyorders c
ON c.ordermonth BETWEEN a.ordermonth AND b.ordermonth
GROUP BY a.ordermonth,b.ordermonth;
运行结果如下图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANUAAADvCAIAAADqwwYfAAARbklEQVR4nO2dwW7buBaG+VSF4Sfoa1y30CJP0W3dFPCuzxAM0kkxgB+gG69vkmZj4M50PHfmXnQxbWonbeqAs5BEUSJFURYPqXN8fmjh0pSsP/xLWvLnY/HT+S+88ZZqEz+d/yJZrEQ6xvzd3t6mPoXwQmcqP2HOHxGhM3W8+fvy5UvqUwgvdKbyE+b8ERE6U5w/UkJnyiN/y0wIIYTIlvFOq6n1YjpdrIMe8vPnz0GP5y0AL0pRTYUwkp+wI3/LTID9tTqlHAKM2d9//+16xeCC9KJkNwWkEEbyEy7y9+PH/v7bQ2378Hoinl80GqNtH15PJq+v9QeBtv3+8a///d/uN+gLRfDSbQp6dIad8N399yJ/Dz/2d/ff9W0mNE1O58+EEM8v7r/fXZ9Oitbyn5Pns4kQQswububFg/Z2+xHy46s+RX8hxOTZc+PZQdt+//jfP/8y/Vav+OrG12NqL52mem+tdhpDL8Tk9KrWMplfN/tfvZrUOhsn7Mpffiz1GuUf692sfHz1aiKevbu7Pp3kr33xXKgHk9Ortnb7EcrjF31aXl09CzFU6hX9Pab2Ejp/Tjvas6Wjd7M8l6pF7399OimfvXhWdmvN38OP3d232nZ1OpmcXuoPzMfi2c9mt/xBZ7t5BOuLtr36odv+8XHzx589/Pp4TOSl21SvzdOObl9fJBv9797N8sb2E97dfeP8cf4G5K9hwWLKnsJm/r4//Nju7mvb5asnk1eX+oPd/XZ3MRNi9vP9dnd/OZ+I2YWlW/6grd1xhEZn8ext49VrZ3Lgtt8/fvz9D7vf/BX9Pab20m2q3+a0s7uYicnLy/LZuv1mZnb328tXs/n1dne/3V2/nBQ7Nk54u7sv8vft+8PX7V1tu5w/eTL/t/5AtZdvoN9au+UP2todR6g/fjsTQogns5n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8x8ZoTPF+SMldKY4f6SEzhTnj5TQmeL8kRI6U375g+OfLUeOJNdQAfLPbS1hFD9/Jv/sajmQP4Xjn40jR5NrqMD4Z2tLQCXJ38rdsqw+Gq4xMlLKsfDP1ZH9ziKE/IYqLP/c3hJIY8yf86me+QPin9saIeU1VIH55/aWQEq4/ir+2UpE50UBB/IvYPxz9MVXpuGf21sCKeH1x1w011afFv/8wfHPCcIn0/DP7S2BlDB/5ns7s0WxqEr+178w/LNx5Gjquv4F4Z9bWwIpdv5M/tlo2SyqFB44/8Hxz7YjR5JjqCD5Z1jeO3b+TP7ZbFk2cWjzhPn+MxGhM8X5IyV0pjh/pITOFOePlNCZquUvMNjKYnlI8vxHRuhMcf5ICZ0pzh8poTPF+SMldKY4f6SEzpRf/oLxwP57gcs1VHD8MzDvHT9//rTzKquK8ir55S8QD+y5Vxy5hgqOfwbmvZPkz4d2XmXyJBtef3cQD9yXiIaV31DB8M/VkQ85c4fS58/21GYhTxax6z+bLT2JaGB5DRUQ/9zWOFgJ19822rkInwyQv4E8MLr8gfHPYMhtwuuPNto5z2K1TWt9/PM3nAfGtf7C8c+AvHfC/HXTzpHrP5stPfaCV9f1Lwz/DMx7x85fL9r54PyF44G99oojx1DB8c/QvHfs/PWinQNcfxASulu1PkJnivNHSuhMcf5ICZ0pzh8poTNVy19gsJXF8pA8zvmPNR5x/lgp9Q+QYPiKfvICHwAAAABJRU5ErkJggg==" alt="" />
该查询首先对MonthlyOrders表进行自连接。a表用做下边界(frommonth),b表用做上边界(tomonth)。连接的条件为:
DATE_ADD(a.ordermonth, INTERVAL 11 MONTH) = b.ordermonth。
例如,a表中的2010年2月将匹配2011年1月。
完成自连接之后,需要对订单进行统计。这时需要再进行一次自连接,得到范围内每个月的订单数量。因此连接的条件为
c.ordermonth BETWEEN a.ordermonth AND b.ordermonth。
基于上述方法,我们还可以统计每个季度订单的情况,以此作为和同比增长的比较依据。

SELECT
DATE_FORMAT(a.ordermonth, '%Y%m') AS frommonth,
DATE_FORMAT(b.ordermonth, '%Y%m') AS tomonth,
SUM(c.ordernum) AS orders
FROM monthlyorders a
INNER JOIN monthlyorders b
ON DATE_ADD(a.ordermonth, INTERVAL 2 MONTH) = b.ordermonth
AND MONTH(a.ordermonth) % 3 = 1
INNER JOIN monthlyorders c
ON c.ordermonth BETWEEN a.ordermonth AND b.ordermonth
GROUP BY a.ordermonth,b.ordermonth;
运行结果如下图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANQAAACWCAIAAAApLDEoAAALSklEQVR4nO2dzU7jSBeG66palq+A2/gC8qKvgm0HWsqOa0Cj9NAaKRfAhvUHNBtL30wP882PWBDohEAIqln4r+wq2+WkjsvncB55YSrlst/US/knbyrip+kvvPDiZRE/TX+RDOOD92i+x8dH34fgHnSiHh8f2XxEQCfqnZrv4eHB9yG4B52oh4cHNh8R0Ili89EBnag2880iIYQQIpr1eFAV4kkYTmKnTc7nc6ftWQOgJadXUS6EzOfzBvPNIgH2VrWSywPosPv7+6Y9OgdSS45ZFBAuhNzf36fme33drJ7XpeXb50AcnFUKe1u+fQ6Cz9fqiqNls3n76+9/zHqd7qgHLe2ioHtntwNOzbd+3TytXtRlJBSC4/G+EOLgbPXydH0cpKXZn8HBKBBCiNHZzThdqS83t5C0n9dJ6wshgv0D7dWdls3m7f9//qXrLfZ4dGOr0beWVlGdl1o5la4XIji+KpUE4+tq/aujoFRZO+Ba8yUN5TvI3qmvo2z96igQ+1+fro+DZMdnByJfCY6v6srNLWTtp3Vq9p6/CtFP+R7tNfrW4tp8jXKUVzNFX0eJKfMStf71cZC9erafVTObb/26fHouLVfHQXB8qa7o62L/Z71astJarrdg3Gnd3rddNm9vt3/82UGvjUZPWtpFdVos5ajy1dNjpf7T11FSWH/AbD423w7mq0gwiDJbsGS+l/XrYrkqLZdHH4KjS3VluVosz0ZCjH5eLZary3EgRmeGaslKXXlDC5XKYv9LZe+lI9ly2Wzevv/+h1lvskd7jb61tIvqtjTKWZ6NRPDpMnu1LL/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k4NIMhs3BKbtbhdE72wqisuMdzLyxfJjjfOk9yRzypDMB6k3v9Ig8lMI6b2t8jMblRL1T/1pCz9kpgM6UWw+OqATxeajAzpRbD46oBM15yQz4xEe+YiAThSbjw7oRLH56IBOFJuPDuhEsfnogE6UhfnAkr2VD7L6/Mndpn7qY05mUpNDlpLM2sxAw52TuTjmKUiyvI6mfoLSG09OshjfTQSRH+vffHpuuWKyi0j5zDeqbt7ptAs2RzFMyqMBu35yq7d5rlIH+Bn5lAzLRVQNsBTzMO8WJgWbk7n3YU96SzLnYRaaeb6xqIZcXE0IDjkn85B+5j4DQK9yNQlx2TcE8xXjnLvZ6AGTzP0Pe9L7nMww+cUBmU+ZjX630y5oktnHsCc9JZkz4skJoe/tlq/50pvcbOTb9YYDOtnb/7Anfc/JDCTZ292ucpF3GqZ/5nceuz1qoQi657E2oBPF5qMDOlFsPjqgE8XmowM6UXNOMjMe4ZGPCOhEsfnogE4Um48O6ESx+eiAThSbjw7oRFmYz1myVy+BTfY20NRPcHoNLbvEl/ksk8xbhUkdJXv1kuZsMyhN/QSmV2/ZLf2brzXJrM7JvNu0uDsle/WSlh+CB8Wun9zq1Vve5sgb8DPyNSaZVXYJk+6Y7NVLwGPlDVj1k2O9bYU74918epI5IYm67JJq2THZq5cM3HzO9eotO2YI5qskmVW2/imE3ZO9esmQT7sQevWWHTMg85mu8PJgaY7l3a6DZK9eMtAbDjC9estu8W4+Pcl8OymlSjuPfO6SvV1maQamoZ/g9Jpa7kkUEO1J5pn5KjA/YH7ITAR0oth8dEAnis1HB3Si2Hx0QCdqzklmxiPvceRjBgKbj/EGm4/xxr8QuvNl7iMaAAAAAABJRU5ErkJggg==" alt="" />

mysql滑动订单问题的更多相关文章

  1. mysql优化---订单查询优化:视图优化+索引创建

    订单的表结构采用了垂直分表的策略,将订单相关的不同模块的字段维护在不同表中 在订单处理这个页面,需要查询各种维度, 因此为了方便查询创建了v_sale_order视图(老版本) drop view v ...

  2. 记一次mysql千万订单汇总查询优化

    公司订单系统每日订单量庞大,有很多表数据超千万.公司SQL优化这块做的很不好,可以说是没有做,所以导致查询很慢. 正题 节选某个功能中的一句SQL EXPLAIN 查看执行计划 EXPLAIN + S ...

  3. mysql滑动聚合

    滑动聚合是按顺序对滑动窗口范围内的数据进行聚合的操作.下累积聚合不同,滑动聚合并不是统计开始计算的位置到当前位置的数据. 这里以统计最近三个月中员工第月订单情况为例来介绍滑动聚合. 滑动聚合和累积聚合 ...

  4. mysql优化---订单查询优化(1):视图优化+索引创建

    订单的表结构采用了垂直分表的策略,将订单相关的不同模块的字段维护在不同表中 在订单处理这个页面,需要查询各种维度, 因此为了方便查询创建了v_sale_order视图(老版本) drop view v ...

  5. mysql优化---订单查询优化:异步分页处理

    订单分页查询: 老的代码是顺序执行查询数据和计算总记录数,但是如果条件复杂的话(比如关联子表)查询的时间要超过20s种 public static PagedList<Map<String ...

  6. MySQL 单笔订单满6个及以上产品且金额>=300赠送优惠券_20161103

    活动内容: 单笔订单满6个及以上产品(帽子.浴巾除外),金额满赠300元,即赠送300-10元(除帽子.浴巾外)优惠券一张.需求数据:满足条件的用户ID活动时间:11.2-11.5(4天)活动规则:① ...

  7. mysql优化---订单查询优化(2):异步分页处理

    订单分页查询: 老的代码是顺序执行查询数据和计算总记录数,但是如果条件复杂的话(比如关联子表)查询的时间要超过20s种 public static PagedList<Map<String ...

  8. 数据库集群 MySQL主从复制

    MySQL主从复制 本节内容我们联系使用MySQL的主从复制功能配置Master和Slave节点,验证数据MySQL的数据同步功能. 因为要使用多个MySQL数据库,所以不建议在电脑上安装多个MySQ ...

  9. BG.Hive - part2

    1. 将mysql的订单数据导入hive的分区表(桶.倾斜)[partition,bucket,skew] a> 在Hive中新建分区表 CREATE TABLE IF NOT EXISTS H ...

随机推荐

  1. Liang-Barsky直线段裁剪算法

    Liang-Barsky直线段裁剪算法 梁友栋与Barsky提出的裁剪算法以直线的参数方程为基础,把判断直线段与窗口边界求交的 二维裁剪问题转化为求解一组不等式,确定直线段参数的一维裁剪问题.设起点为 ...

  2. Eclipse配置python开发环境

    1.打开Eclipse,找到Help菜单栏,进入Install New Software…选项. 点击work with:输入框的旁边点击Add…,Name可以随便是什么,我输入的是PyDev,Loc ...

  3. android6.0以上权限动态申请,有视频链接可以看效果。

    android6.0以上某些权限需要动态申请,虽然现在大多的手机系统版本在6.0,但是升级到6.0及以上是迟早的事,所以如何能够更好的控制动态申请权限时能有好的提示用户,及给用户带去更好的体验,是需要 ...

  4. 图像之王ImageMagick

    这是我目前能想到的名字.很久前某图像群看到有人推荐过,试了一下确实厉害,支持的格式之多让人叹服. http://www.imagemagick.org/script/formats.php 一般用法 ...

  5. appium 1.6.x版本去除安装Unlock、Setting

    (appium目录不知道可以查看appium运行日志) 修改目录/usr/local/lib/node_modules/appium/node_modules/appium-android-drive ...

  6. 记一次需要用到复杂的groupingBy的需求

    一:先定义结构 public class Foo { private Integer id; private String name; private BigDecimal amount; publi ...

  7. HTTP lab01 做一个简单的测试用 web页面

      做一个简单的测试用 web页面     1.安装httpd服务   yum install httpd   安装完httpd服务后,系统就自动生成了/var/www/html目录     创建一个 ...

  8. 生成图形化html报告

    生成图形化html报告: 1.从cmd 进入执行测试文件 2.执行该命令:jmeter -n -t <test JMX file> -l <test log file> -e ...

  9. latex 希腊字母表示

    http://blog.sina.com.cn/s/blog_5e16f1770100lxq5.html

  10. 我的C#跨平台之旅(六):发布应用

    由于此架构从一开始就将.NET Framework 的依赖降低到最低,且不依赖IIS,在ORM层面,完全实现代码优先,即真正做到数据库无关: Windows服务器部署: 在Windows应用服务器上安 ...