再开一贴,没有解决

artak 2008-01-14 11:39:02
编号 审批者 审批时间 主单号
1001 aa 2008-2-14 AM 10:15:17 1 122
1002 aa 2008-2-14 AM 10:14:00 1 122
1003 bb 2008-2-14 AM 10:14:00 1 122
1004 aa 2008-2-14 AM 10:14:00 1 122
1005 cc 2008-2-14 AM 10:14:00 1 122
1006 aa 2008-2-14 AM 10:14:00 1 123
1007 dd 2008-2-14 AM 10:14:00 1 124

如上面,一个审批者aa审批了一个单号为122,123的单据,他的审批步骤插入上表,是1001,1002,1004,其中1006是另外一个单据的
我要从这个审批记录表读出aa所审核过的单据,由于aa可能审核了多步骤,如上,怎么选择出aa所审核的所有单子,编号为1001,1002,1004其实是同一个主单122,选出aa所审批单据应该只有122,123
...全文
121 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
primulaling 2008-01-15
  • 打赏
  • 举报
回复
select distinct 审批者,主单号
from tb
where 审批者='aa'

审批者 主单号
aa 122
aa 123
tim_spac 2008-01-15
  • 打赏
  • 举报
回复
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

主单号
-----------
122
123
草原可可 2008-01-15
  • 打赏
  • 举报
回复
select 审批者,主单号 from 表名 group by 审批者,主单号
junshanhudazhaxi 2008-01-14
  • 打赏
  • 举报
回复
select   *   from   tb   
where 主单号 in(select 主单号 from tb where 审批者='aa' group by 审批者,主单号 )
and 审批者='aa'
junshanhudazhaxi 2008-01-14
  • 打赏
  • 举报
回复
select * from tb
where 主单号 in(select 主单号 from tb where 审批者='aa' group by 审批者,主单号 )
and 审批者='aa'
jhkII 2008-01-14
  • 打赏
  • 举报
回复
select distinct 审批者,主单号 from 表名 where 审批者='aa'
liangCK 2008-01-14
  • 打赏
  • 举报
回复
lz想要的结果是怎么样的?

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 行)

*/
pt1314917 2008-01-14
  • 打赏
  • 举报
回复

楼主没有把期望的结果贴出来,只有猜了

这样?
select 审批者,主单号 from 表名 group by 审批者,主单号

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧