2

我有一个表 ( l.loandeterminationscore),它返回由 3 个 # (XXX) 组成的结果。我正在使用以下查询将该结果分成 aLowRange和 a HighRange,以便我可以将返回的结果分组为一个结果“XXX-XXX”。

SELECT 
    l.LoanNumber,
    l.LoanDeterminationScore 'FICO', 
    FLOOR (l.LoanDeterminationScore / 20) * 20 AS LowRange,
    FLOOR (l.loanDeterminationScore / 20) * 20 + 19 AS HighRange
FROM 
    loan.LoanQA l
WHERE
    l.FundedDate = '10/15/2013'

从上面返回的结果是这样的:

LoanNumber FICO LowRange HighRange
-----------------------------------
592301428  604  600      619
220300002  640  640      659
414805244  675  660      679

我正在尝试使用and将上述内容分组FICO为 20pt 范围。所以简而言之,我希望它不是有两列,而是作为一列返回,显示范围为“600-619”、“640-659”、“660-679”。LowRangeHighRangeLowRangeHighRange

我试图CONCAT表达,但我不断收到“语法”错误。

4

1 回答 1

1

试试这个:

SELECT 
    l.LoanNumber,
    l.LoanDeterminationScore 'FICO', 
    CAST(FLOOR (l.LoanDeterminationScore / 20) * 20 AS VARCHAR(10)) + '-' +
    CAST(FLOOR (l.loanDeterminationScore / 20) * 20 + 19 AS VARCHAR(10)) AS 'Range' 
FROM 
    loan.LoanQA l
WHERE
    l.FundedDate = '10/15/2013'

只是CAST字符串类型的数值,与 连接+,你就完成了!

于 2013-10-17T13:45:45.873 回答