0

次のフィールドを持つ tblClients という名前のテーブルがあります: idClient、name、credit、debt。

Create table tblClients(idClient int,name varchar(20), credit int, debt int);
insert into tblClients values(1,'Guillermo',1000,0),(2,'Jess',5000,2000);

借金の種類を次のように分類したい

debt = 0 NOT                DEBTOR
debt between 0 AND 1000     LOW DEBTOR
debt between 1001 AND 2000  MEDIUM DEBTOR.

このクエリを実行すると、債務者のタイプが取得されます。

SELECT name AS 'Client',debt AS 'Debtor Type' FROM tblClients WHERE debt = 0;
SELECT name AS 'Client',debt AS 'Debtor Type' FROM tblClients WHERE debt BETWEEN 1 AND 1000;

債務番号の代わりにDEBTORLOW DEBTORまたはタグを列の債務に入れるにはどうすればよいですか?MEDIUM DEBTOR

4

1 に答える 1

2

これを試して:

SELECT name AS Client, 
CASE 
    WHEN debt = 0 THEN 'Not Debtor'
    WHEN debt BETWEEN 1 AND 1000 THEN 'Low Debtor'
    ELSE 'Medium Debtor'
END AS debt
FROM tblClients 
于 2012-05-04T19:42:58.673 に答える