日期:2014-05-17 浏览次数:20528 次
select name from (
select * from UC uc1
where city in ( select city from UC uc2 where uc2. name =' 张三 ')
and city not in ( select city from UC uc3 where uc3 .city not in ( select city from UC uc4where uc4. name =' 张三 '))
and uc1 . name <> ' 张三 '
) tmp
group by name
having COUNT ( city) = ( select COUNT (city ) from UC where name = '张三 ' )
;with t as(
SELECT name, value = stuff((SELECT ',' + city
FROM #TABLE1 AS t
WHERE t .name = #TABLE1.name FOR xml path('')), 1, 1, '')
FROM #TABLE1
GROUP BY name
)
select name from t where name<>'张三'
and value=(select value from t where name='张三')