【问题标题】:please someone explain what exactly last line is doing [duplicate]请有人解释最后一行到底在做什么[重复]
【发布时间】:2018-09-30 17:36:21
【问题描述】:
SELECT A.siebel_row_id AS ASSET_ROW_ID,A.SIEBEL_STATUS ,B.STATUS AS THINDB_STATUS
FROM OR_ASSET_THINDB A ,THINDBUSER.MSI B
WHERE A.msisdn=B.msisdn`enter code here`
and b.circle='Orissa'
and DECODE(a.siebel_status,'Suspended','Active','Active','Active','Inactive','Inactive')<>b.STATUS; 

【问题讨论】:

  • Bad habits to kick : using old-style JOINs - 旧式 逗号分隔的表格列表 样式已替换为 ANSI 中的 proper ANSI JOIN 语法-92 SQL 标准(25 多年前),不鼓励使用它
  • 查看DECODE 函数并尝试使用CASE expression 重写它。这会让事情变得更清楚。对于您和其他阅读该代码的人。

标签: sql oracle


【解决方案1】:

我不确定这个查询要求,但这是我的理解

DECODE(siebel_status,'Suspended','Active','Active','Active','Inactive','Inactive')
这将如下所示:

case  
when siebel_status = 'Suspended' THEN 'Active'  
when siebel_status = 'Active' THEN 'Active'  
when siebel_status = 'Inactive' THEN 'Inactive'
end;

上面返回的结果将与以下内容进行比较:
b.STATUS;

所以最终的答案可能是这样的:
if('Active','Active','Inactive')b.STATUS

【讨论】:

    【解决方案2】:
    and DECODE(a.siebel_status, 
               'Suspended', 'Active',
               'Active'   ,'Active' ,
               'Inactive' ,'Inactive'
              ) <> b.STATUS;
    

    上面写着:

    • 如果 siebel_status 暂停,则假装它是活动
    • 如果 siebel_status 是 active,那么 - 它是 active 反正
    • 如果 siebel_status inactive,则它保持 inactive

    然后将其与 b.status 值进行比较。

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2012-07-25
      • 2016-05-10
      • 2015-03-06
      • 2016-06-02
      • 2021-04-07
      • 2019-09-05
      • 1970-01-01
      • 2015-07-08
      相关资源
      最近更新 更多