2016-05-14 126 views
0

我在「工作訪問報告可接受性」中構建報告。這裏是我當前的查詢:在查詢中合併兩個字段

SELECT 
    tblSTATUS.Status, Count(tblJOB.StatusTypeID) AS CountOfStatusTypeID 
FROM 
    tblSTATUS 
INNER JOIN 
    tblJOB ON tblSTATUS.StatusTypeID = tblJOB.StatusTypeID 
GROUP BY 
    tblSTATUS.Status 
HAVING 
    (((tblSTATUS.Status) = "Completed" OR 
     (tblSTATUS.Status) = "Accepted" OR 
     (tblSTATUS.Status) = "Rejected")); 

而且這裏的結果:

Status   CountofStatusTypeID 
Accepted     22 
Completed     4 
Rejected     3 

不幸的是,我需要在接受和完成的字段合併報告,因爲他們都是「接受」的工作。我無法找到將這兩者結合起來的方法,並仍然在報告中顯示被拒絕的價值。我知道如何編寫一個查詢來獲得Accept或Rejected結果,但不知道如何將它們組合到Access報告中可以使用的東西中。

+0

你能不添加另一個字段狀態表? – Fionnuala

回答

0

這是否正常工作?

SELECT "completed and accepted" as jobstatus, Count(tblJOB.StatusTypeID) AS CountOfStatusTypeID 
FROM tblSTATUS INNER JOIN tblJOB ON tblSTATUS.StatusTypeID = tblJOB.StatusTypeID 
where tblSTATUS.Status="Completed" Or tblSTATUS.Status="Accepted" 
union 
SELECT tblSTATUS.Status as jobstatus, Count(tblJOB.StatusTypeID) AS CountOfStatusTypeID 
FROM tblSTATUS INNER JOIN tblJOB ON tblSTATUS.StatusTypeID = tblJOB.StatusTypeID 
where tblSTATUS.Status="Rejected"; 
+0

不幸的不是。 Access對於新的jobstatus列有困難,因爲它不是「集合函數的一部分」。訪問必須是我曾經使用過的最令人沮喪的程序之一。感謝您的幫助。 – Phantomwang

0
SELECT 
    newtblSTATUS.newstatus, Count(tblJOB.StatusTypeID) AS CountOfStatusTypeID 
FROM 
    (
SELECT 
    iif(tblSTATUS.Status='Rejected','Rejected','Accepted') as newstatus, tblSTATUS.StatusTypeID 
FROM 
    tblSTATUS 
where tblSTATUS.Status in ("Completed","Accepted","Rejected")) as newtblSTATUS 
INNER JOIN 
    tblJOB ON newtblSTATUS.StatusTypeID = tblJOB.StatusTypeID 
GROUP BY 
    newtblSTATUS.newstatus 
+0

這工作完美。謝謝! – Phantomwang