ich folgenden Fall Aussage gegen meine Kreditnehmer Tabelle habenerstellen niedrigen und hohen Bereich mit Case-Anweisung
SELECT borrower_id,
CASE
WHEN bo.fico_score >= 0 AND bo.fico_score <= 599 THEN '0-599'
WHEN bo.fico_score >= 600 AND bo.fico_score <= 649 THEN '600-649'
WHEN bo.fico_score >= 650 AND bo.fico_score <= 699 THEN '650-699'
WHEN bo.fico_score >= 700 AND bo.fico_score <= 749 THEN '700-749'
WHEN bo.fico_score >= 750 AND bo.fico_score <= 800 THEN '750-800'
WHEN bo.fico_score > 800 AND bo.fico_score <= 850 THEN '801-850'
END AS "Borrower FICO"
from borrowers bo;
Der Anwendungsfall erfordert ich für einen niedrigen Bereich und hohen Bereich anstelle der oben genannten. Der folgende Code funktioniert.
SELECT borrower_id,
CASE
WHEN bo.fico_score >= 0 AND bo.fico_score <= 599 THEN '0'
WHEN bo.fico_score >= 600 AND bo.fico_score <= 649 THEN '600'
WHEN bo.fico_score >= 650 AND bo.fico_score <= 699 THEN '650'
WHEN bo.fico_score >= 700 AND bo.fico_score <= 749 THEN '700'
WHEN bo.fico_score >= 750 AND bo.fico_score <= 800 THEN '750'
WHEN bo.fico_score > 800 AND bo.fico_score <= 850 THEN '801'
END AS "Borrower FICO LOW",
CASE
WHEN bo.fico_score >= 0 AND bo.fico_score <= 599 THEN '599'
WHEN bo.fico_score >= 600 AND bo.fico_score <= 649 THEN '649'
WHEN bo.fico_score >= 650 AND bo.fico_score <= 699 THEN '699'
WHEN bo.fico_score >= 700 AND bo.fico_score <= 749 THEN '749'
WHEN bo.fico_score >= 750 AND bo.fico_score <= 800 THEN '800'
WHEN bo.fico_score > 800 AND bo.fico_score <= 850 THEN '850'
END AS "Borrower FICO HIGH",
from borrowers bo;
Ich glaube nicht, dass es sehr gutes Design ist. Gibt es eine bessere Möglichkeit, diese Case-Anweisung zu schreiben, so dass ich einen niedrigen und hohen Bereich für einen Kreditnehmer Kredit-Score bieten kann? ‚-‘
Wenn Sie Zeichenfolgen verwenden, warum nicht einfach so etwas wie ' '600-649''. –
@GordonLinoff Dies ist, was ich in meiner ursprünglichen Abfrage hatte, aber die Anforderungen wurden geändert. – Alan