读书人

请问!

发布时间: 2012-01-21 21:31:43 作者: rapoo

请教!!!!!
有这样一个表
票号 序号 档案号
0001 1 a
0001 2 a
0001 3 a
0001 1 b
0002 1 a
0003 1 a
0003 2 a
0004 1 a
0004 1 b
想查出档案号中一起出现过AB的票号

[解决办法]
select distinct 票号 from 表 t where t.档案号= 'a ' and exists(select 1 from 表 where 票号=t.票号 and 档案号= 'b ')

读书人网 >SQL Server

热点推荐