日期:2014-05-17 浏览次数:21076 次
WorkNoInfo(员工表)
Id WorkNo GroupId
1 701 78
2 302 24
3 702 78
tableC(工单表)
OrderNo WorkNo
20130925001 701
20130925002 701
20130925003 702
20130925004 302
selct count(*) from tableC where(后面的语句要继续写下去)
create table #WorkNoInfo(id int,workno varchar(50),groupid varchar(50))
insert into #WorkNoInfo
select 1,701,78 union all
select 2,302,24 union all
select 3,702,78
go
create table #tableC(OrderNo varchar(50),WorkNo varchar(50))
insert into #tableC
select 20130925001,701 union all
select 20130925002,701 union all
select 20130925003,702 union all
select 20130925004,302
go
select count(*) from #tableC where WorkNo
in(select WorkNo from #WorkNoInfo where groupid=
( select groupid from #WorkNoInfo where workno='701')
)
create table WorkNoInfo
(Id int, WorkNo int, GroupId int)
insert into WorkNoInfo
select 1, 701, 78 union all
select 2, 302, 24 union all
select 3, 702, 78
create table tableC
(OrderNo varchar(16), WorkNo int)
insert into tableC
select '20130925001', 701 union all
select '20130925002', 701 union all
select '20130925003', 702 union all
select '20130925004', 302
select count(1) '工单数量'
from tableC where WorkNo in
(select WorkNo from WorkNoInfo where GroupId=
(select top 1 GroupId from WorkNoInfo where WorkNo=701))
/*
工单数量
-----------
3
(1 row(s) affected)
*/
create table WorkNoInfo
(Id int, WorkNo int, GroupId int)
insert into WorkNoInfo
select 1, 701, 78 union all