ID REALNAME SEX
1 10082 松XX
2 10084 林XX 1
3 10087 西XX
4 10100 胡XX
5 10102 龙XX 1
用法============
select u.id,u.realname,
( case u.sex
when 1 then ‘男‘
when 2 then
‘女‘
else ‘空的‘
END
) 性别
from users u;
====
第二种情况 如果A字段不为空 就用A字段;如果为空就用B字段
select t.epvd_name , t.FF , count(t.epod_id) from (
select epv.epvd_name ,CASE WHEN to_char(epod.epod_create_time,‘yyyyMM‘) is NULL THEN to_char(epod.epod_update_time,‘yyyyMM‘) ELSE to_char(epod.epod_create_time,‘yyyyMM‘) END FF , epod.epod_id
from ep_order_detail epod
left join ep_vendor epv on epv.epvd_id = epod.vendor_id
where epod.epod_status > 0
and epv.epvd_status=1) t
group by t.epvd_name ,t.FF
order by t.FF
注意:起的别名 不能用于本次排序;
时间: 2024-10-11 01:01:36