为什么内部联接不与PostgreSQL中的case子句一起使用

时间:2019-03-20 10:20:21

标签: sql postgresql

我有这个SQL查询,但是这行不通,我很困惑为什么这行不通。有人为此提供示例或解决方案吗?

SQL:

select e.state 
       case when  e.state = 'a' then 'cation'  else 'pasive' end 
from miss as e INNER JOIN 
     mr as a 

错误:

  

“ case”处或附近的语法错误            在e.id = a.id;

Solution: select e.state , 
       case when  e.state = 'a' then 'cation'  else 'pasive' end 
from miss as e INNER JOIN 
     mr as a 

1 个答案:

答案 0 :(得分:2)

SELECT
  e.state,    -- you were missing a , here
  case when e.state = 'a' then 'cation'  else 'pasive' end 
from
  miss as e
INNER JOIN 
  mr as a
    -- You're missing the join predicate here : ON e.something = a.something

如果没有一些示例数据或对要实现的目标的任何描述,则可能没有联接谓词,因为您确实打算使用UNION

SELECT
  e.state,
  case when e.state = 'a' then 'cation'  else 'pasive' end 
FROM
(
   SELECT * FROM miss
   UNION ALL
   SELECT * FROM mr
)
  e