我有两张桌子
表oc_1234567890
| time | S363 | S342 |
| 2015-04-20 22:39:17 | 19.12 | 19.43 |
| 2015-04-20 22:36:49 | 19.12 | 19.43 |
| 2015-04-20 22:34:20 | 19.12 | 19.43 |
| 2015-04-20 22:31:52 | 19.12 | 19.43 |
| 2015-04-20 22:29:23 | 19.18 | 19.43 |
表oc_1122334455
| time | S352 |
| 2015-04-20 22:38:03 | 15.68 |
| 2015-04-20 22:35:34 | 15.68 |
| 2015-04-20 22:33:06 | 15.68 |
| 2015-04-20 22:30:38 | 15.68 |
| 2015-04-20 22:28:09 | 15.68 |
需要将它按时间合并到1,2或5分钟 并从1440年获取200条记录 期待这样的数组:
$array = [
"2015-04-20 22:38" => {
"S352" => "15.68", "S363" => "19.12", "S342" => "19.43", }
"2015-04-20 22:35" => {
"S352" => "15.68", "S363" => "19.12", "S342" => "19.43", }
"2015-04-20 22:33" => {
"S352" => "15.68", "S363" => "19.12", "S342" => "19.43", }
"2015-04-20 22:30" => {
"S352" => "15.68", "S363" => "19.12", "S342" => "19.43", }
"2015-04-20 22:28" => {
"S352" => "15.68", "S363" => "19.18", "S342" => "19.43", }
];
请帮忙提出建议!
答案 0 :(得分:1)
这个怎么样?
SELECT LEFT(时间,16)分钟,S352,S342,S363 FROM oc_1234567890 a JOIN oc_1122334455 b ON LEFT(a.time,16)= LEFT(b.time,16)
对于大型数据集,这将非常慢。我可能会创建一个中间映射表,将time
映射到您想要的1,2或5分钟内部。