是否可以使用IN子句返回select语句的结果?

时间:2013-07-02 22:14:56

标签: sql tsql

我正在尝试做这样的事情:

select ('hi' in ('hi')) as hi

由于“in”部分的语法错误,它无法正常工作。

是否可以使用IN子句返回子查询的布尔结果?

3 个答案:

答案 0 :(得分:4)

您可以使用CASE

来使用条件表达式
select
    case when 'hi' in ('hi') then 1 else 0 end

Here is a demo on sqlfiddle

答案 1 :(得分:2)

尝试CASE,例如

select 
  case 
     when 'hi' in ('hi') then 1 else 0 
 end as hi

答案 2 :(得分:2)

我相信你能做的就是使用case语句将条件值返回一点:

select case when 'hi' in ('hi') then 1 else 0 end as hi