【发布时间】:2013-07-06 23:56:41
【问题描述】:
我需要从有 2 个主键 macid 和 deviceid 的表中选择数据。
我需要记录集按这 2 个主键对记录进行分组,但我不知道该怎么做。
这就是我现在拥有的:
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}
]
这就是我需要的L
[
[{"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
这可能吗??
【问题讨论】:
-
你是通过 Python 做的吗?并且您需要在 Python 端列表上进行分组吗?
-
嗨,我正在为这个应用程序使用 javascript。我希望记录集返回 2 个单独的记录,以便 js cn 然后循环遍历每个 mac/device 组。
标签: javascript sql sqlite