0

我在列表TaskListGridView1右侧列出我正在显示工人列表having different skills under oneserviceCategoryID。点击GridView1Row 和所有Workers with multiple skills under one serviceCategoryID are Listed in GridView2.

在将任务分配给任何工人之前,我想显示该PendingTasks工人的GridView2数量List of Workers with multiple skills under one selected serviceCategoryID from GridView1.

当前的 SQL 查询是:

SELECT WorkerMst.workerID, WorkerMst.FName, WorkerMst.LName,WorkerMst.FName +' '+ WorkerMst.LName as Name,WorkerSkills.WorkerSkillsID,
     WorkerSkills.WorkerID AS WorkerSkills_WorkerID, WorkerSkills.SkillTypeID AS WorkerSkills_SkillTypeID, WorkerSkills.Score, skillTypeMst.skillTypeID, skillTypeMst.skillType, 
     serviceCategoryMaster.serviceCategoryMasterID, serviceCategoryMaster.CategoryName, WorkerMst.IsActive AS WorkerMst_IsActive,WorkerMst.IsIndividual,WorkerMst.readyfornewtask,
     (select count(WorkerID)from WorkerTask where isAproved=0 and workerid in (select distinct(workerid) from workertask where isaproved=0 group by workerid)) as PendingTsks

 FROM WorkerMst 
 INNER JOIN WorkerSkills ON WorkerMst.workerID = WorkerSkills.WorkerID 
 INNER JOIN skillTypeMst ON WorkerSkills.SkillTypeID = skillTypeMst.skillTypeID 
 INNER JOIN serviceCategoryMaster ON skillTypeMst.serviceCategoryMasterID = serviceCategoryMaster.serviceCategoryMasterID
where skillTypeMst.serviceCategoryMasterID=1 and 
WorkerMst.workerID in (select distinct(workerid) from workertask where isaproved=0)
order by workermst.workerid

在此处输入图像描述

WorkerTask表具有以下字段:

WorkerID,TaskMstID,IsAccepted ,IsRejected,OnDate,isAproved

有什么建议吗?帮助赞赏!提前致谢!

4

2 回答 2

1

您尚未提供表的架构,但我假设该WorkerTask表将有一行用于分配给(任何)工作人员的任务。我假设这WorkerTaskId是该表的主键,那么以下查询就足够了:

SELECT 
     WorkerMst.workerID, WorkerMst.FName, WorkerMst.LName,
     WorkerMst.FName +' '+ WorkerMst.LName as Name,WorkerSkills.WorkerSkillsID,
     WorkerSkills.WorkerID AS WorkerSkills_WorkerID, 
     WorkerSkills.SkillTypeID AS WorkerSkills_SkillTypeID, WorkerSkills.Score,
     skillTypeMst.skillTypeID, skillTypeMst.skillType, 
     serviceCategoryMaster.serviceCategoryMasterID, serviceCategoryMaster.CategoryName, 
      WorkerMst.IsActive AS WorkerMst_IsActive, WorkerMst.IsIndividual, 
      WorkerMst.readyfornewtask,
     (select count(t.workertaskid)from WorkerTask t
         where t.isAproved=0 and t.workerid = WorkerMst.workerid) as PendingTsks
 FROM WorkerMst 
 INNER JOIN WorkerSkills ON WorkerMst.workerID = WorkerSkills.WorkerID 
 INNER JOIN skillTypeMst ON WorkerSkills.SkillTypeID = skillTypeMst.skillTypeID 
 INNER JOIN serviceCategoryMaster 
    ON skillTypeMst.serviceCategoryMasterID =  serviceCategoryMaster.serviceCategoryMasterID
where skillTypeMst.serviceCategoryMasterID=1 
order by workermst.workerid
于 2013-01-11T10:15:20.890 回答
0

这是修改后的查询:

SELECT 
     WorkerMst.workerID, WorkerMst.FName, WorkerMst.LName,
     WorkerMst.FName +' '+ WorkerMst.LName as Name,WorkerSkills.WorkerSkillsID,
     WorkerSkills.WorkerID AS WorkerSkills_WorkerID, 
     WorkerSkills.SkillTypeID AS WorkerSkills_SkillTypeID, WorkerSkills.Score,
     skillTypeMst.skillTypeID, skillTypeMst.skillType, 
     serviceCategoryMaster.serviceCategoryMasterID, serviceCategoryMaster.CategoryName, 
      WorkerMst.IsActive AS WorkerMst_IsActive, WorkerMst.IsIndividual, 
      WorkerMst.readyfornewtask,(select count(workerid)from WorkerTask 
         where isAproved=0 and workerid = WorkerMst.workerid) as PendingTsks

 FROM WorkerMst 
 INNER JOIN WorkerSkills ON WorkerMst.workerID = WorkerSkills.WorkerID 
 INNER JOIN skillTypeMst ON WorkerSkills.SkillTypeID = skillTypeMst.skillTypeID 
 INNER JOIN serviceCategoryMaster 
    ON skillTypeMst.serviceCategoryMasterID =  serviceCategoryMaster.serviceCategoryMasterID
where skillTypeMst.serviceCategoryMasterID=1 and WorkerSkills.Score>=70
order by workermst.workerid

感谢@VinayC 的建议!

于 2013-01-11T10:42:29.780 回答