这是方案
表1:
select buyprice,sellprice,datetime from zebpay order by id desc limit 10
# buyprice, sellprice, datetime
'1107705', '1057858', '2017-12-24 13:30:23'
'1105060', '1053927', '2017-12-24 13:25:23'
'1106381', '1056594', '2017-12-24 13:20:23'
'1115181', '1064998', '2017-12-24 13:15:22'
'1112749', '1062675', '2017-12-24 13:10:21'
'1111888', '1061853', '2017-12-24 13:05:21'
'1128365', '1080974', '2017-12-24 13:00:20'
'1127202', '1079859', '2017-12-24 12:55:20'
'1132226', '1084672', '2017-12-24 12:50:19'
'1132037', '1084492', '2017-12-24 12:45:19'
表2:
select buyprice,sellprice,datetime from coinsecure order by id desc limit 10
# buyprice, sellprice, datetime
'1045000', '1042100', '2017-12-24 13:32:44'
'1050000', '1045000', '2017-12-24 13:31:43'
'1050000', '1042100', '2017-12-24 13:30:41'
'1045000', '1042100', '2017-12-24 13:29:39'
'1048000', '1042100', '2017-12-24 13:28:37'
'1048000', '1042100', '2017-12-24 13:27:35'
'1048000', '1042000', '2017-12-24 13:26:33'
'1050000', '1048199', '2017-12-24 13:25:30'
'1050000', '1048199', '2017-12-24 13:24:29'
'1050000', '1048199', '2017-12-24 13:23:27'
我想通过首先将table1 buyprice与table2买入价格相加然后根据所有日期时间的每一分钟找到平均值来获得买入价和卖出价的平均值
例如,我应该得到一个像这样的表# buyprice,sellprice,datetime
'1045000', '1042100', '2017-12-24 13:55:00'
'1050000', '1045000', '2017-12-24 13:50:00'
'1050000', '1042100', '2017-12-24 13:45:00'
'1045000', '1042100', '2017-12-24 13:40:00'
'1048000', '1042100', '2017-12-24 13:35:00'
'1048000', '1042100', '2017-12-24 13:30:00'
'1048000', '1042000', '2017-12-24 13:25:00'
'1050000', '1048199', '2017-12-24 13:20:00'
'1050000', '1048199', '2017-12-24 13:15:00'
'1050000', '1048199', '2017-12-24 13:10:00'
这里所有的值都在2017-12-24 13:55:00 2017-12-24 13:50:00之间 用于在2017-12-24 13:55:00获得平均值
它可以是5分钟或1分钟或1小时的间隔。要点是获得尽可能多的精确图形值。
如果一个表中的值在给定的时间间隔内不存在,则可以取零