select * from generic_shop
where (type, timestamp) in (
select type, max(timestamp)
from generic_shop
group by type
) order by type
如果在命令行中进行了测试,则此查询有效,但在某个房间中它声称where (type, timestamp)
处有错误。我如何重写它以使其正常工作?预先感谢。
答案 0 :(得分:1)
SQLite不支持涉及左侧多列的IN
子句。但是,您的查询很容易使用其他方式表示:
SELECT g1.*
FROM generic_shop g1
INNER JOIN
(
SELECT type, MAX(timestamp) AS max_timestamp
FROM generic_shop
GROUP BY type
) g2
ON g1.type = g2.type AND g1.timestamp = g2.max_timestamp;
ORDER BY
g1.type;