sql中关于case when的一个例子

Posted xue123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql中关于case when的一个例子相关的知识,希望对你有一定的参考价值。

SELECT rownum R,
a.expert_id as USERID,
a.expert_id as TYPE,
b.type_desc as TYPE_DESC,
a.sex as SEX,
a.user_name as USERNAME,
a.head_portrait as HEADPORTRAIT,
h.hospital_name as HOSPITAL,
H.H_LEVEL AS HLEVEL,
c.jobtitle_name as JOBTITLE,
d.dept_name as DEPT,
e.price as PRICE,
e.time as TIME,
a.introduce as INTRODUCE,
CASE
WHEN (SELECT COUNT(*)
FROM T_GROUP_RELATION X
WHERE X.USER_ID = v_userId
AND X.FRIEND_ID = a.expert_id) > 0 THEN
1
ELSE
0
END AS ISFRIEND
from T_EXPERT_INFO a,
T_EXPERT_TYPE_INFO b,
T_JOBTITLE c,
T_HOSPITAL h,
T_DEPT d,
T_EXPERT_PRICE_INFO e
where a.expert_type = b.type_id
and a.jobtitle_id = c.jobtitle_id
and a.hospital_id = h.HOSPITAL_ID
and a.dept_id = d.dept_id
and e.expert_id = a.expert_id
ORDER BY a.create_time DESC

以上是关于sql中关于case when的一个例子的主要内容,如果未能解决你的问题,请参考以下文章

sql case when的使用

sql 中 case when 语法

SQL学习- case when then else

SQL学习- case when then else

SQL学习- case when then else

SQL学习- case when then else