SQL:带有"存在"的case-when语句

Chr*_*ris 4 sql teradata

我希望能够设置添加一个回答问题的字段"对于此记录中的值,该值是否满足另一个表中的某些条件?".我想我会尝试case-whenexists,但Teradata的(我DBMS)不喜欢它.有什么建议?

select foo,
   (case when exists (select x.foo
                      from somedb x
                      where x.bar > 0)
    then '1' else '0' end) as MyFlag

from mydb
Run Code Online (Sandbox Code Playgroud)

mar*_*ton 11

看起来你错过ENDCASE声明?

select foo,
   (case when exists (select x.foo
                      from somedb x
                      where x.bar > 0)
    then '1' else '0' END) as MyFlag

from mydb
Run Code Online (Sandbox Code Playgroud)