2012-08-03 50 views
0

我在MVC3工作指望在這裏,我需要一些幫助,請如何編寫一個查詢,選擇需要的列,並從不同的表

這裏我有一個像(錯誤ID)

錯誤ID標題描述專案編號版本的一些表BuildNumber EmployeId類別ID創建日期嚴重性ID PriorityID發行版ID類型ID

2銀行業務應用程序1新版本新建版否1 1 00:00:00。00 1 1 1 1

(項目表)

================================= ======================

Projectid ProjectName Description  Status 

1 Finance  This is Finance Project Active 
2 Uniformatic This is Finance Project Active 
3 ProDuct  This is Finance Project InActive 
4 Cloud  This is Finance Project INActive 
5 Banking  This is Finance Project Progress 

6電子商務這是融資項目活動

RealesePhase(表)

== ================================================== ================

ReleasePhaseID ReleasePhase 

1  DEV 
2  QA 
3  Alpha 
4  Beta 

5直播

Tostatus(表)

=============================== ====================

ToStatusId  Tostatus 

1  New 
2  Assigned 
3  Fixed 
4  Re-Opened 
5  Closed 
6  Deffered 

7不是錯誤

Bughistory(表)

BugHistoryID錯誤ID FixedByID AssignedTo分辨率FromStatus ToStatus

5     2   1   1  this is my banking  New   New 
7     2   1   1  this assignto res    km,l 

========================================= ================================================== ===========

這裏我有這些表現在我必須編寫一個查詢來選擇ProjectName(下拉) 和(ReleasePhase)從它(open)(closed)(fixedBy)

在Bugs表中錯誤將從它的日誌(插入),所以現在我們必須選擇項目名稱& ReleasePhase作爲下拉,如果我們選擇項目名稱,我應該得到我們對它的錯誤數(計數)

從它像 (視圖)謹此

================================ =====================================

項目名RealesePhase openBugs ClosedBugs fixedBy

    1   New   EmployeName 
       2   Assigned EmployeName 
       3   Fixed  EmployeName 
       4   Re-Opened EmployeName 

=============================================== =======================

所以PLZ幫我寫一個查詢計數和顯示Ë多少錯誤插入的員工,有多少被釋放,有多少收

在此先感謝

回答

1

你最好使用this..and存儲過程,我認爲你需要的bug數量,按您的狀態表和Releasephase和ProjectId ..這是我看到你的問題希望它可以幫助你...

Create procedure [dbo].[ProjectReports] 
(
@ProjectID int, 
@ReleasePhaseID int 
) 
as 
begin 
select distinct projectName,ReleasePhase, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='New')) as Newbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Assigned')) as Assignedbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Fixed')) as Fixedbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Re-Opened')) as Reopenedbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Closed')) as Closedbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Deffered')) as Defferedbugs, 
(Select COUNT(1) from Bugs where ProjectId=a.ProjectId and ReleasePhaseID=a.ReleasePhaseID and 
bugid in (select BugID from BugHistory where [status]='Not a Bug')) as NotaBug 
from Bugs a 
inner join Projects p on p.ProjectId=a.ProjectId 
inner join ReleasePhase Rp on rp.ReleasePhaseID=a.ReleasePhaseID 
where [email protected] and [email protected] 
end 
相關問題