标签:
连续聚合是按时间顺序对有序数据进行聚合的操作。
CREATE TABLE EmpOrders ( empid INT NOT NULL, ordermonth DATE NOT NULL, qty INT NOT NULL,test PRIMARY KEY (empid,ordermonth) );
INSERT INTO EmpOrders SELECT a.employeeid,orderdate AS Order date,SUM(quantity) AS qty FROM orders a INNER JOIN orderdetails b ON a.orderid=b.orderid GROUP BY employid,DATE_FORMAT(orderdate,‘%Y-m‘);
下面给出生成示例数据的php文件
<?php $sql = "INSERT INTO emporders SELECT %s,‘%s-%02d-01‘,%s;".‘<br />‘; $insert_sql = ‘‘; for($empid=1;$empid<=8;$empid++) { for($year=2009;$year<=2015;$year++) { for($month=1;$month<=12;$month++) { $num = rand(20,800); $insert_sql .= sprintf($sql,$empid,$year,$month,$num); } $insert_sql .= ‘<br />‘; } } echo $insert_sql;
标签:
原文地址:http://www.cnblogs.com/chenqionghe/p/4679730.html