日期:2014-05-17  浏览次数:20681 次

查询进度问题
要求全输入的,按拆分后的子段做统计,输入部分的,按输入的做统计
--数据
if object_id('tempdb.dbo.#A') is not null drop table #A
create table #A(List_id varchar(10), F_ListID varchar(10))
insert into #A
select '112','111' union all
select '113','111' union all
select '111','111' union all
select '213','211' union all
select '212','211' union all
select '211','211' union all
select '313','311' union all
select '312','311' union all
select '311','311' union all
select '413','411' union all
select '412','411' union all
select '411','411' union all
select '513','511' union all
select '512','511' union all
select '511','511' union all
select '613','611' union all
select '612','611' union all
select '611','611' 

if object_id('tempdb.dbo.#A') is not null drop table #B
create table #B(List_id varchar(10), Status varchar(10))
insert into #B
--全输入的,拆分后的子段全完成的为完成
select '112','完成' union all
select '113','完成' union all
select '111','未接收' union all
select '213','在操作' union all
select '212','完成' union all
select '211','完成' union all
--输入部分的,按输入的完成为完成
select '312','在操作' union all
select '313','完成' union all
select '412','完成' union all
select '411','在操作' union all
select '511','在操作' union all
select '613','在操作' 

--结果
F_ListID   Status
---------- ------
111        完成
211        在操作
311        在操作
411        完成
511        在操作
611        在操作

------解决方案--------------------
USE test
GO
 
if object_id('tempdb.dbo.#A') is not null drop table #A
create table #A(List_id varchar(10), F_ListID varchar(10))
insert into #A
select '112','111' union all
select '113','111' union all
select '111','111' union all
select '213','211' union all
select '212','211' union all
select '211','211' union all
select '313','311' union all
select '312','311' union all
select '311','311' union all
select '413','411' union all
select '412','411' union all
select '411','411' union all
select '513','511' union all
select '512','511' union all
select '511','511' union all
select '613','611' union all
select '612','611' union all
select '611','611' 
 
if object_id('tempdb.dbo.#B') is not null drop table #B
create table #B(List_id varchar(10), Status varchar(10))
insert into #B
--全输入的,拆分后的子段全完成的为完