借用case when
<!--個人中心列表展示 union 因爲上部是可以和patent匹配的數據,而下面是用戶自己輸入的可能在patent裏沒有記錄的公開號信息,辣眼睛-->
<select id="selectPersonCenterList" resultMap="BasePatentMonitorSetVO">
select * from( select a.abs,b.project_name,a.patent_id,a.id,a.pubNumer ,a.appDate,a.title,
a.applicationName,a.lprs,a.patent_level,a.appNumer,a.pubDate,
a.iapp,a.ipub,a.divideInitAppNo,a.priority,a.inventroName,a.sameApp,a.den,a.agencyName
from (select b.id as patent_id,a.project_id,a.id,a.pubNumber as pubNumer ,b.title,a.apply_date as appDate,
a.apply_name as applicationName,a.lprs,
CASE a.patent_level WHEN '一級' THEN 1
WHEN '二級' THEN 2
ELSE 3 END
as patent_level,
b.appNumer,b.pubDate,
b.iapp,b.ipub,b.divideInitAppNo,b.priority,b.inventroName,b.sameApp,b.den,b.agencyName,b.abs from patent_monitoring_set a,patent b
where a.pubNumber=b.pubNumer and a.emp_id=#{map.empId} )a left join patent_project b
on a.project_id=b.id
union
select null as abs,b.project_name,null as patent_id,c.id,c.pubNumer,c.appdate as appDate,c.title,c.applicationname as applicationName,c.lprs,c.patent_level,c.appNumer,c.pubDate,
c.iapp,c.ipub,c.divideInitAppNo,c.priority,c.inventroname,c.sameApp,c.den,c.agencyName from (select a.project_id,id,a.pubNumber as pubNumer,null as title,a.apply_date as appdate,a.apply_name as applicationname,
a.lprs,
CASE a.patent_level WHEN '一級' THEN 1
WHEN '二級' THEN 2
ELSE 3 END
as patent_level,
null as appNumer, null as pubDate,
null as iapp,null as ipub,null as divideInitAppNo, null as priority,
null as inventroname,null as sameApp,
null as den,null as agencyName
from patent_monitoring_set a where a.emp_id=#{map.empId} and a.id not in(select a.id from patent_monitoring_set a,patent b
where a.pubNumber=b.pubNumer and a.emp_id=#{map.empId}))c left join patent_project b
on c.project_id=b.id)c
WHERE 1=1
<if test="map.projectName!='all'">
and c.project_name like concat('%',#{map.projectName},'%')
</if>
<if test="map.pubNumber!='' and map.pubNumber!=null">
and c.pubNumer like concat('%',#{map.pubNumber},'%')
</if>
</select>
one two more
SELECT id,CASE 'teacher' WHEN 'dd' THEN 'one'
WHEN 2 THEN 'two'
ELSE 'more' END
as testCol from employee