日期:2014-05-18 浏览次数:20610 次
SELECT T1.TITLE+'['+CASE WHEN T2.ID IS NOT NULL THEN 'YES' ELSE 'NO' END)+']' FROM [表1] T1 LEFT JOIN ( SELECT MID,MAX(ID) AS ID FROM [表2] GROUP BY MID ) T2 ON T1.ID=T2.MID
------解决方案--------------------
select a.title + case when b.id is not null then 'yes' else 'no' end from 表1 a left join 表2 b on a.id=b.mid
------解决方案--------------------
select title+(case when exists(select 1 from 表2 where mid=a.id) then 'yes' else 'no' end) from 表1 a