3

我是否可以覆盖列中的值,以便如果情况为真,它会告诉值 x 等于查询中的另一个动态值。这是伪代码。我知道这行不通。

Select jobTitle, managerTitle, bigBossTitle,
    CASE WHEN jobtitle like '%DEVELOP%' THEN managerTitle = bigBossTitle
    END 
From PeopleTable
inner join... other tables...

谢谢。

4

4 回答 4

4

试试这个:

Select     
    jobTitle, 
      CASE WHEN jobtitle like '%DEVELOP%' 
      THEN bigBossTitle 
      ELSE managerTitle 
      END as managerTitle, 
    bigBossTitle,

From PeopleTable
inner join... other tables...

您只需将 case 语句放在 managerTitle 列所在的位置,然后将结果别名为 managerTitle。这种逻辑有效地为您提供了您正在寻找的东西。要真正“替换”一个值,您需要执行更高级的 T-SQL,这并不是真正必要的。

在连接谓词中使用 case 语句的示例:

...
inner join otherTable 
on otherTable.bossTitle = 
      CASE WHEN jobtitle like '%DEVELOP%' 
      THEN bigBossTitle 
      ELSE managerTitle 
      END
于 2012-12-13T21:40:09.353 回答
1

试试这个:

Select jobTitle,
    CASE
        WHEN jobtitle like '%DEVELOP%'
        THEN bigBossTitle
        ELSE managerTitle 
    END as managerTitle,
   bigBossTitle
From PeopleTable
inner join... other tables...
于 2012-12-13T21:40:55.340 回答
1

你非常亲近。你CASE会是这样的:

Select jobTitle, bigBossTitle,
    CASE 
          WHEN jobtitle like '%DEVELOP%' 
          THEN bigBossTitle 
          ELSE managerTitle
    END as managerTitle
From PeopleTable
inner join... other tables...
于 2012-12-13T21:41:00.890 回答
0

尝试这样的事情:

Select jobTitle, managerTitle, bigBossTitle, IF(jobtitle like '%DEVELOP%', bigBossTitle, OTHER_VALUE_IF_FALSE) AS managerTitle 
From PeopleTable
inner join... other tables...
于 2012-12-13T21:38:51.107 回答