0

好吧,我是菜鸟,我接受。但我试图结合这两个查询,由于某种原因我不明白如何。

查询 1。

select t.id from tickets t

查询 2。

SELECT name 
FROM groups 
WHERE id = (
            SELECT DISTINCT immediateparentid 
            FROM cachedgroupmembers c
            LEFT JOIN groups g
            ON c.groupid = g.id
            LEFT JOIN tickets t
            ON t.id = g.instance
            WHERE t.Id = 1234
            AND g.type = 'AdminCc'
            AND immediateparentid <> c.groupid
        )

第一个查询中的票证 ID 用于第二个查询的 where 子句。有没有办法结合这两个查询?

4

1 回答 1

0
SELECT 
        g.name,
        (SELECT id FROM tickets) as ID
FROM groups as g
WHERE id = (
            SELECT 
                DISTINCT immediateparentid 
            FROM cachedgroupmembers c
            LEFT JOIN groups g ON c.groupid = g.id
            LEFT JOIN tickets t ON t.id = g.instance
            WHERE t.Id = ID
            AND g.type = 'AdminCc'
            AND immediateparentid <> c.groupid
        )       

这是一个依赖子查询

于 2013-01-04T18:27:06.977 回答