我需要所有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;
现在我被卡住了。
答案 0 :(得分:3)
这么简单吗?
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 ...
答案 1 :(得分:1)
尝试以下 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;