下面是我想使用的"贷款金额"的语法列。我正在创建用于报告的ssa数据集。但是我在添加"贷款id"时遇到了问题。列,因为我需要"贷款金额"one_answers"贷款编号";在同一个数据集中。如何整合"LOAN id"?同时保留下面的"贷款金额"的语法。
SELECT DISTINCT
CASE
WHEN [LoanAmount] <= 100000 THEN 'Less Than $100k'
WHEN [LoanAmount] BETWEEN 100000 AND 200000 THEN '$100k to $200k'
WHEN [LoanAmount] > 200000 THEN 'More Than $200k'
END [LoanAmount]
FROM
[dbo].[dim loan detail]
如果只需要添加LOAN_ID,只需在SELECT之后和FROM之前用逗号分隔每列。同样,在这种情况下,"DISTINCT"关键字不需要,因为每个LOAN_ID都是唯一的,因此是不同的。
SELECT
LOAN_ID,
CASE
WHEN [LoanAmount] <= 100000 THEN 'Less Than $100k'
WHEN [LoanAmount] between 100000 AND 200000 THEN '$100k to $200k'
WHEN [LoanAmount] > 200000 THEN 'More Than $200k'
END [LoanAmount]
FROM [dbo].[dim loan detail]