1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CASE式の入れ子(ネストされたCASE式)の書き方

Posted at

CASE式を入れ子で書けることを知ったので、忘れないように書いておきます。

テーブル

BILL_DATE PAYMENT CARD_COMPANY
2022/01/08 2 null
2022/01/11 99 99
2022/01/12 99 2
2022/01/13 1 null
2022/01/17 99 3
2022/01/19 99 1
2022/01/22 2 null
2022/01/24 99 2

SELECT文

SELECT
	BILL_DATE AS 請求日,
	CASE PAYMENT
		WHEN '1' THEN '口座振替入金'
		WHEN '2' THEN '振込入金'
		ELSE
			CASE CREDIT_CARD_COMPANY
				WHEN '1' THEN 'VISA'
				WHEN '2' THEN 'MASTERCARD'
				WHEN '3' THEN 'AMERICAN EXPRESS'
				ELSE '不明'
			END
	END 支払方法
FROM
	BILLING_TB
;

結果

請求日 支払方法
2022/01/08 振込入金
2022/01/11 不明
2022/01/12 MASTERCARD
2022/01/13 口座振替入金
2022/01/17 AMERICAN EXPRESS
2022/01/19 VISA
2022/01/22 振込入金
2022/01/24 MASTERCARD
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?