我正忙着完成旧的考试试卷
一个问题如下:
研究下表并回答以下问题:
CREATE TABLE CARDHOLDERS(
CH_ID INTEGER IDENTITY,
CH_NAME VARCHAR(50),
CH_SURNAME VARCHAR(50),
CH_IDNUMBER CHAR(13),
CH_CARDNUMBER CHAR(13),
CH_STATUS CHAR(2),
CH_CREATE_DATE DATETIME,
CH_LAST_CHANGE_DATE DATETIME)
CARDHOLDER_STATUS //apologies if this is wrongly formatted
CHS_STATUS CHS_DESCRIPTION
00 Active
01 Not Active
撰写查询以获取以下结果
Cardholder Status
Ashton, T Active
Brown, C Active
Crawford, C Not Active
Ellis, J Active
我假设我必须使用完全外连接,因为两个表中没有列匹配。 我写了这段代码,但它给了我一个语法错误。
SELECT CH_NAME, CH_SURNAME
FROM CARDHOLDERS
FULL OUTER JOIN
ON CARDHOLDER_STATUS.CHS_STATUS, CARDHOLDER_STATUS.CHS_DESCRIPTION
答案 0 :(得分:1)
如果没有看到示例数据,我希望他能够“正常工作”:
SELECT ch.CH_SURNAME + ', ' + LEFT(ch.CH_NAME, 1) AS Cardholder,
chs.CHS_DESCRIPTION AS Status
FROM CARDHOLDERS AS ch
INNER JOIN CARDHOLDER_STATUS AS chs
ON chs.CHS_STATUS = ch.CH_STATUS
答案 1 :(得分:0)
试试这个
SELECT CH_NAME+','+ CH_SURNAME,CHS_Description
FROM CARDHOLDERS C
JOIN CARDHOLDER_STATUS S on S.CHS_STATUS = C.CH_STATUS