我有一種情況我不確定它是否可以執行。
我有兩個表我需要加入並使用計數。SQL 2012將連接多個表的多個查詢連接起來並統計到一個表中
表1 = 「EPM_ProjectUserview」
[ProjectUID], [ProjectName], [EnterpriseProjectTypeUID](used as a filter)
表2 = 「EpmTask_UserView」
[ProjectUID],[Task_Significance], [TaskPercentCompleted] then 3 count fields
[total Count], [Count 100% complete], Count <1005]
這會給我的表看起來像這樣
注:有一個第一列不適合項目名稱
|Apps|Overall% Comp| Totl Count|100% Compl|Not 100% Comp|Overall Health|
同一行的接口將是真實的
總體%完整和整體健康來自於摘要任務
(這是項目服務器)
ProjectUID是加入一個重點領域。
所以我有5個不同的查詢,所有的工作,但當然我需要他們在1表。
查詢1 - 這是項目名稱projectUID和EnterpriseprojecttypeUID
SELECT [ProjectName]
,[ProjectUID]
,[EnterpriseProjectTypeUID]
FROM [dbo].[MSP_EpmProject_UserView]
where [projectUID] not like '0000CF75-FB12-4FFC-A404-AEC4F3258A9C'
And
[EnterpriseProjectTypeUID] like '76194144-3CDB-E611-9419-00215A9259E8'
order by [ProjectName]
查詢2這使我每種類型
SELECT p.[ProjectName]
,T.[Task_Significance]
-- ,T.[TaskPercentCompleted]
,count (*) as [Total Count]
FROM [psmado].[dbo].[MSP_EpmProject_UserView] as P
join [PSMADO].[dbo].[MSP_EpmTask_UserView] as T
On T.[projectUID] = P.[projectUID]
where
([Task_Significance] like 'App'
Or
[Task_Significance] like 'Interface')
Group by [ProjectName], [Task_Significance]
查詢3-下一查詢的總數給我的100 %完成列
SELECT p.[ProjectName]
,T.[Task_Significance]
-- ,T.[TaskPercentCompleted]
,count (*) as [Count]
FROM [psmado].[dbo].[MSP_EpmProject_UserView] as P
join [PSMADO].[dbo].[MSP_EpmTask_UserView] as T
On T.[projectUID] = P.[projectUID]
where T.[TaskPercentCompleted] >= 100
and
([Task_Significance] like 'App'
Or
[Task_Significance] like 'Interface')
Group by [ProjectName], [Task_Significance]
查詢4 - 下一個給我的那個少一些N 100%完成
SELECT p.[ProjectName]
,T.[Task_Significance]
-- ,T.[TaskPercentCompleted]
,count (*) as [Count]
FROM [psmado].[dbo].[MSP_EpmProject_UserView] as P
join [PSMADO].[dbo].[MSP_EpmTask_UserView] as T
On T.[projectUID] = P.[projectUID]
where T.[TaskPercentCompleted] < 100
and
([Task_Significance] like 'App'
Or
[Task_Significance] like 'Interface')
Group by [ProjectName], [Task_Significance]
查詢5最後整個任務的健康和%完全來自不同的行中的表
SELECT [dbo].[MSP_EpmProject_UserView].[ProjectName]
,[dbo].[MSP_EpmTask_UserView].[ProjectUID]
,[dbo].[MSP_EpmTask_UserView].[TaskName] as [Name]
,[dbo].[MSP_EpmTask_UserView].[TaskPercentCompleted] as [% Complete]
,[dbo].[MSP_EpmTask_UserView].[Task Health] as [Health]
,[dbo].[MSP_EpmTask_UserView].[Task_Significance]
,[dbo].[MSP_EpmTask_UserView].[TaskOutlineNumber]
FROM [dbo].[MSP_EpmTask_UserView]
inner join [PSMADO].[dbo].[MSP_EpmProject_UserView]
on [dbo].[MSP_EpmTask_UserView].[projectuid] = [PSMADO].[dbo].[MSP_EpmProject_UserView].[ProjectUID]
where [dbo].[MSP_EpmTask_UserView].[projectUID] not like '0000CF75-FB12-4FFC-A404-AEC4F3258A9C' -- the timesheet project null
and [Task_Significance] like 'App Summary'
or [Task_Significance] like 'Interface Summary'
order by [ProjectName], [TaskOutlineNumber]
難道這被(工會是不工作的投入一個表我)如果是這樣怎麼樣?
感謝您的幫助
這就是我所得到的。你可以看到它只是重複每個部分。 (我砍掉了它的一部分,但也有36行。)
向我們展示db架構,示例數據和預期輸出。 \t請閱讀[**如何提問**](http://stackoverflow.com/help/how-to-ask) \t \t這裏是一個偉大的地方[** START **] (http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)來了解如何提高您的問題質量並獲得更好的答案。 –
什麼意思'這些可以放在一張桌子上嗎? –