此查询返回给定特定traceid
值(本例中为 50,这是两个表中都存在的键)我需要的数据,tblResults
并且tblTraces
:
SELECT count(changed)
FROM (
SELECT changed
FROM tblResults
WHERE traceid = 50
AND changed = 1
ORDER BY resultid DESC
LIMIT 0,20
) as R
我想对几乎所有查询运行上面的查询traceid
(因此,为每个 traceid 选择 20 行,而不仅仅是 traceid 50,所以 3 个 traceid 意味着 60 行)。下面这个简单的选择获取所需的traceid
值:
SELECT `traceid` FROM `tblTraces` WHERE `enabled` = 1
如何将两个查询“粘合”在一起?
所以我想象一个像下面这样的查询,除了它不起作用,因为子查询返回多行(我想要的):
SELECT count(changed)
FROM (
SELECT changed
FROM tblResults
WHERE traceid = (
SELECT `traceid` FROM `tblTraces` WHERE `enabled` = 1
)
AND changed = 1
ORDER BY resultid DESC
LIMIT 0,20
) as R