【问题标题】:SQL check if numrical value is 0 for a field where id is=333SQL检查id=333的字段的数值是否为0
【发布时间】:2012-10-19 11:23:41
【问题描述】:

在 SQL SELECT CASE STATEMENT 中,我将如何检查 sometable 中某个 coulmn 的值是否等于 0 而 id 等于某个值?

【问题讨论】:

  • 你能发布一个示例语句吗?在 case 语句中涉及子查询的答案将起作用,但可能表现不佳。可能有更好的方法来获得您的结果。

标签: sql select-case


【解决方案1】:
select
    case
        when (select column_name from sometable where id = @id) = 0 then
        else 
    end

【讨论】:

    【解决方案2】:
    select 
     case when( select column from table where id=333)=0 then "your condition"
    else
    end
    

    【讨论】:

      【解决方案3】:

      我对你的问题的解释:

      SQL 检查字段 (Field1) 的数值是否为 0 [仅当 id=333 时]
      [如果id不是333,则不需要检查]

      SELECT CASE WHEN isnull(id,0) <> 333 OR Field1=0 THEN 1 ELSE 0 END
            ,other1, other2
        FROM tbl
      

      【讨论】:

        猜你喜欢
        • 2013-05-27
        • 1970-01-01
        • 2015-12-13
        • 1970-01-01
        • 1970-01-01
        • 2011-05-13
        • 1970-01-01
        • 1970-01-01
        • 2011-06-03
        相关资源
        最近更新 更多