0

假设我有一个包含三列的表:user_to、user_from、counter。我正在尝试做一个查询,检查是否从同一个表中进行交叉引用检查。也许这将有助于理解:

SELECT user_to AS user_to1
    , user_from AS user_to2
FROM tbl
WHERE counter > 10
    AND NOT EXISTS (
        SELECT *
        FROM tbl
        WHERE user_to = user_from1
            AND user_from = user_to1
        )

我假设我试图做错了,但查询有助于理解我想要完成的事情。

4

1 回答 1

0

你可以ALIAS在上面添加一个,

SELECT user_to AS user_to1
    , user_from AS user_to2
FROM tbl a
WHERE counter > 10
    AND NOT EXISTS (
        SELECT *
        FROM tbl b
        WHERE b.user_to = a.user_to
            AND b.user_from = a.user_from
        )
于 2012-10-22T07:42:13.287 回答