根据多个ID条件显示列中的结果

时间:2016-03-10 12:06:23

标签: sql database validation ms-access-2010

这是我的疑问:

SELECT Reference.quote_date As Date, Customer.name As Name ,
       Customer.surname AS Surname, Customer.postcode, Customer.telephone,
       Reference.ref_ID AS PolicyRefNo, Reference.agent_ID,
FROM Customer INNER JOIN
     Reference
     ON Customer.customer_ID = Reference.customer_ID;

我想添加其他列,以显示Tel或F2F活动的结果

因此,如果reference.call_id = 1,reference.call_id = 2或reference.call_id = 3,那么结果将显示在名为Tel as 1的新列中

如果reference.call_id = 4,reference.call_id = 5,reference.call_id = 6,那么结果将在名为F2F的新列中显示为1

我目前正在开发Access数据库 任何建议将不胜感激

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

SELECT Reference.quote_date As Date, Customer.name As Name ,
       Customer.surname AS Surname, Customer.postcode, Customer.telephone,
       Reference.ref_ID AS PolicyRefNo, Reference.agent_ID,
       (reference.call_id IN(1,2,3))  as Tel,
       (reference.call_id IN(4,5,6)) as F2F
FROM Customer INNER JOIN
     Reference
     ON Customer.customer_ID = Reference.customer_ID;

答案 1 :(得分:0)

SELECT Reference.quote_date As Date, Customer.name As Name , Customer.surname AS Surname , Customer.postcode, Customer.telephone, Reference.ref_ID AS PolicyRefNo, Reference.agent_ID,
CASE WHEN Reference.call_id IN ('1','2','3') THEN '1'
         ELSE '0' END AS Tel
     CASE WHEN Reference.call_id IN ('4','5','6') THEN '1'
         ELSE '0' END AS F2F

FROM Customer INNER JOIN Reference ON Customer.customer_ID = Reference.customer_ID;