34,837
社区成员




create table tb(编号 int,审批者 char(2),审批时间 datetime,主单号 int)
insert into tb select 1001, 'aa' , '2008-2-14 10:15:17', 122
insert into tb select 1002 , 'aa' , '2008-2-14 10:14:00', 122
insert into tb select 1003 , 'bb' , '2008-2-14 10:14:00', 122
insert into tb select 1004 ,'aa' , '2008-2-14 10:14:00', 122
insert into tb select 1005 ,'cc' , '2008-2-14 10:14:00', 122
insert into tb select 1006 ,'aa', '2008-2-14 10:14:00', 123
insert into tb select 1007 ,'dd', '2008-2-14 10:14:00', 124
select distinct 主单号
from tb
where 审批者='aa'
drop table tb
select * from tb
where 主单号 in(select 主单号 from tb where 审批者='aa' group by 审批者,主单号 )
and 审批者='aa'
create table tb(编号 int,审批者 char(2),审批时间 datetime,主单号 int)
insert into tb select 1001, 'aa' , '2008-2-14 10:15:17', 122
insert into tb select 1002 , 'aa' , '2008-2-14 10:14:00', 122
insert into tb select 1003 , 'bb' , '2008-2-14 10:14:00', 122
insert into tb select 1004 ,'aa' , '2008-2-14 10:14:00', 122
insert into tb select 1005 ,'cc' , '2008-2-14 10:14:00', 122
insert into tb select 1006 ,'aa', '2008-2-14 10:14:00', 123
insert into tb select 1007 ,'dd', '2008-2-14 10:14:00', 124
select *
from tb
where 审批者='aa' and (主单号 in(122,123))
order by 编号
drop table tb
/*
编号 审批者 审批时间 主单号
----------- ---- ------------------------------------------------------ -----------
1001 aa 2008-02-14 10:15:17.000 122
1002 aa 2008-02-14 10:14:00.000 122
1004 aa 2008-02-14 10:14:00.000 122
1006 aa 2008-02-14 10:14:00.000 123
(所影响的行数为 4 行)
*/
楼主没有把期望的结果贴出来,只有猜了
这样?
select 审批者,主单号 from 表名 group by 审批者,主单号