昨日思路集中在连接上了,如用MYSQL
select st_id from ttn
group by st_id
having(
instr(concat(',',group_concat(st_cur),','),',a,')>0
and
instr(concat(',',group_concat(st_cur),','),',b,')=0)
or
select a1.st_id from (
select st_id from ttn where st_cur='A' group by st_id) a1
left join
(select st_id from ttn where st_cur='b' group by st_id) b1
on a1.st_id=b1.st_id
where isnull(b1.st_id)
select A1.* from ttn a1 left join (
SELECT A.* FROM TTN A LEFT JOIN TTN B ON (B.st_id=A.st_id ) WHERE A.st_cur='B' ) b1
on B1.st_id=A1.st_id WHERE A1.st_cur='A'
AND ISNULL(B1.st_id)
不用EXISTS
select A1.* from ttn a1 left join (
SELECT A.* FROM TTN A LEFT JOIN TTN B ON (B.st_id=A.st_id ) WHERE A.st_cur='B' ) b1
on B1.st_id=A1.st_id WHERE A1.st_cur='A'
AND ISNULL(B1.st_id)