1、多个字段的判断,case 后不指定字段,使用when来判断多个字段

  

SELECT
	A.id,NAME,description,
	CASE 
		 WHEN	ISNULL(apply_status) THEN 4
		 WHEN	(A.enabled=0) THEN 3
	ELSE apply_status
  END status
FROM
	tm_vinterface A
	LEFT JOIN th_interface_apply_history B ON A.id = B.interface_id 
	AND B.account_id = 1047 
	AND B.enabled = 1

  

2、单个字段的判断,case 接固定字段,按照值处理

  

SELECT
	A.id,NAME,description,
	CASE apply_status
		 WHEN	0 THEN "申请中"
		 WHEN	1 THEN  "通过"
	ELSE "驳回"
  END status
FROM
	tm_vinterface A
	LEFT JOIN th_interface_apply_history B ON A.id = B.interface_id 
	AND B.account_id = 1047 
	AND B.enabled = 1

  

 

相关文章:

  • 2022-12-23
  • 2022-02-24
  • 2021-12-10
猜你喜欢
  • 2021-05-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
相关资源
相似解决方案