在查询中过滤 SELECT 结果

时间:2020-12-23 06:51:47

标签: sql oracle

我有一个关于这种结构的查询:

SELECT distinct
    ...,
    ...,
    (CASE WHEN 
        (select ... from ... where ...) 
    IS NULL 
        THEN 'Site' ||LOWER((
            select ... from ... where ... and ...))
    ELSE 
            (select ... 
            from ...
            where ...)
  END) as importantResult
FROM
  ...
WHERE
  ...

现在我只需要从 importantResult 的结果中过滤一个值。我无法在 WHERE 中指定此项。

我该怎么办?

1 个答案:

答案 0 :(得分:4)

使用“this”作为 CTE;然后过滤。

例如:

with temp as
  (select distinct ... <your query goes here>
          ... as importantResult
   from ...
  )
select whatever
from temp
where importantResult = some_value