0

我正在尝试创建一个查询,其中第一个查询将返回 COLUMN,基于第一个查询的结果,第二个查询将执行:

SELECT OBJECT_ID from test.CORRELATION_SET
WHERE (NAME='STATUS' AND VALUE ='SUCCESS')
|OBJECT_ID|
|---------|
|A        |
|B        |
|C        |
|---------|
SELECT * FROM test.CORRELATION_SET
WHERE OBJECT_ID = ('A'|'B'|'C');
4

2 回答 2

3

以下是查询

SELECT * FROM CORRELATION_SET
WHERE OBJECT_ID in (
  SELECT OBJECT_ID from CORRELATION_SET
  WHERE (NAME='STATUS' AND VALUE ='SUCCESS')
)
于 2013-04-28T05:57:19.910 回答
1

您的示例并没有真正意义,看起来您在第二个查询中错过了命名表。

SELECT * from test.CORRELATION_SET WHERE (NAME='STATUS' AND VALUE ='SUCCESS')

上述查询将返回与您的两个查询相同的结果。假设您的第二个查询使用了一个名为 的表CORRELATION_SET2,您可以使用 Kumar 在他的评论中使用的嵌套查询。您也可以使用连接。

SELECT set2.* FROM test.CORRELATION_SET set1
    JOIN test.CORRELATION_SET2 set2 ON set2.object_id = set1.object_id
WHERE
  set1.name = 'status' and set1.value = 'success';
于 2013-04-28T05:58:01.010 回答