我需要从有 2 个主键 macid 和 deviceid 的表中选择数据。
我需要记录集按这两个主键对记录进行分组,但我不知道该怎么做。
这就是我现在所拥有的:
SELECT * FROM data WHERE stamp > 1373040000000 AND stamp < 1373126400000 ORDER BY macid ASC,deviceid ASC,stamp ASC
[
{"deviceid":1,"temp":-19.81,"macid":"19:5d:ee3e00","stamp":1373054400000},
{"deviceid":1,"temp":-20.31,"macid":"19:5d:ee3e00","stamp":1373065200000},
{"deviceid":3,"temp":28.87,"macid":"19:5d:ee3e00","stamp":1373054400000},
{"deviceid":3,"temp":28.87,"macid":"19:5d:ee3e00","stamp":1373065200000}
]
这就是我需要的
[
[{"deviceid":1,"temp":-19.81,"macid":"19:5d:ee3e00","stamp":1373054400000},
{"deviceid":1,"temp":-20.31,"macid":"19:5d:ee3e00","stamp":1373065200000}]
[{"deviceid":3,"temp":28.87,"macid":"19:5d:ee3e00","stamp":1373054400000},
{"deviceid":3,"temp":28.87,"macid":"19:5d:ee3e00","stamp":1373065200000}]
]
我已经尝试过了,但它只返回与第一个结果相同的结果:
SELECT * FROM data WHERE stamp > 1373040000000 AND stamp < 1373126400000 GROUP BY macid, deviceid, stamp ORDER BY macid ASC,deviceid ASC,stamp ASC
这可能吗 ??