【问题标题】:Creating a case expression with a join statement; Oracle使用 join 语句创建 case 表达式;甲骨文
【发布时间】:2018-05-06 21:35:05
【问题描述】:

我需要所有Library_ID 以是或否的形式返回。它们是 1、2 或 3,因此我需要将 1、2 或 3 的所有内容更改为是,将所有其他内容更改为否。到目前为止,这是我的声明:

SELECT DISTINCT 
    Title, Publisher, Release_Date, ISBN, l.Library_ID
FROM  
    Catalog_Item c
INNER JOIN 
    Book b ON c.Catalog_Item_ID = b.Catalog_Item_ID
INNER JOIN 
    Physical_Item p ON c.Catalog_Item_ID = p.Catalog_Item_ID
INNER JOIN 
    Branch br ON p.Branch_ID = br.BRranch_ID
INNER JOIN 
    Library l ON br.Library_ID = l.Library_ID
ORDER BY 
    Title;

现在我被卡住了。

【问题讨论】:

标签: sql oracle case


【解决方案1】:

就这么简单吗?

SELECT DISTINCT
    Title, Publisher, Release_Date, ISBN,
    case when l.Library_ID in (1,2,3) then 'Yes' else 'No' end as Library_ID
From ...

【讨论】:

    【解决方案2】:

    试试下面的CASE表达式:-

    SELECT DISTINCT Title, Publisher, Release_Date, ISBN, l.Library_ID, CASE WHEN l.Library_ID IN (1,2,3) THEN 'YES' ELSE 'NO' END AS "YES_OR_NO" FROM
    Catalog_Item c INNER JOIN Book b ON c.Catalog_Item_ID = b.Catalog_Item_ID INNER JOIN Physical_Item p ON c.Catalog_Item_ID = p.Catalog_Item_ID INNER JOIN Branch br ON p.Branch_ID = br.BRranch_ID INNER JOIN Library l ON br.Library_ID = l.Library_ID ORDER BY Title;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多