2012-02-13 64 views
0

我需要計算每個技術人員在解決月份爲 2012年1月的門票時花費的總天數,並按升序列出它們。簡單的SQLPLUS問題..我的回答是錯誤的

我試圖改寫這一問題使其在第一所以這裏

更清晰的找到所有在2012年1月的月票高科技PPLS並顯示花費在每個總天數。

繼承人我嘗試

select pplSoft, days_worked_on as pplWorkedOn 
from Tickets, Tech_personnel 
where date_submitted >= '01-JAN-2012' AND date_submitted <= '31-JAN-2012' 
group by pplSoft having pplWorkedOn = 
    (select days_worked_on WHERE date_submitted >= '01-JAN-2012' 
    AND date_submitted <= '31-JAN-2012'); 

哪項是錯誤的...幫助表示讚賞!

TECH PERSONNEL (pplSoft, fname, lname, pittID, expertise, office phone) where fname is first name, and lname is last name. 

USERS (pplSoft, fname, lname, pittID, office phone) 

CATEGORIES (category id, category, description) where this table lists all possible categories of submitted tickets. 

INVENTORY(machine name, IP, network port, MACADDR, location id) 

LOCATIONS(location id, location, building, notes) 

TICKETS (ticket number, owner pplSoft, date submitted, date closed, days worked on, category id, machine name, location, description) 

ASSIGNMENT (ticket number, tech pplSoft, date assigned, status) where status held is an enumeration, could be: assigned, in progress, delegated, closed successful, or closed unsuccessful. 

回答

0
SELECT owner_pplSoft, SUM(days_worked_on) AS sum_days_worked_on 
FROM Tickets 
WHERE date_submitted >= '01-JAN-2012' AND date_submitted <= '31-JAN-2012' 
GROUP BY owner_pplSoft 
ORDER BY SUM(days_worked_on) 
0

如果我理解正確的模式...

SELECT PPLSOFT, SUM(DAYS_WORKED_ON) 
FROM TECH_PERSONNEL, TICKETS 
WHERE TECH_PERSONNEL.PPLSOFT = TICKETS.OWNER 
AND DATE_SUBMITTED >= TO_DATE('1/1/2012', 'DD/MM/YHYYY') 
AND DATE_SUBMITTED <= TO_DATE('31/1/2012', 'DD/MM/YYYY') 
GROUP BY PPLSOFT 
ORDER BY PPLSOFT 

ORDER BY SUM(DAYS_WORKED_ON) DESC 

取決於您要

0

我希望這是一個右:

select pplSoft, sum(TO_CHAR(todays_worked_on,'mm-dd-yyyy')) 
from Tickets tc, Tech_personnel tp 
where tp.pplSoft=tc.pplSoft 
and (date_submitted between TO_DATE('01-01-2012','mm-dd-yyyy') 
and TO_DATE('01-31-2012','mm-dd-yyyy')) 
group by pplSoft,TO_CHAR(todays_worked_on,'mm-dd-yyyy') 
0
SELECT owner_pplSoft as pplSoft, SUM(days_worked_on) AS pplWorkedOn 
FROM tickets 
WHERE date_submitted >= to_date('01-JAN-2012', 'dd-mon-yyyy') 
    AND date_submitted <= to_date('31-JAN-2012', 'dd-mon-yyyy') 
GROUP BY owner_pplSoft 
ORDER BY SUM(days_worked_on) 
0

的門票PPLSOFT列是所有者,而不是在機票上工作的人。要獲得技術人員,您需要將ASSIGNMENTS包含在組合中。

select tech.pplSoft 
     , sum(tic.days_worked_on) as pplWorkedOn 
from Tickets tic 
     join assignments ass on (ass.ticket = tic.ticket) 
     join Tech_personnel tech on (ass.pplSoft = tech.pplSoft) 
where ass.date_submitted >= to_date('01-JAN-2012') 
and ass.date_submitted <= to_date('31-JAN-2012') 
group by tech.pplSoft 

現在這可能仍然不會爲您提供您想要的答案。這是因爲您的數據模型存在缺陷。

DAYS_WORKED_ON列保存在TICKET級別,所以如果兩個人在票上工作,天數將被重複計算。此外,1月份爲2011年12月31日籌集的機票工作的日子不計算在內。要獲得準確的數字,您需要跟蹤每個人在工單上工作的日期。

雖然ASSIGNMENTS.STATUS列似乎持有與TICKET有關的狀態。不確定這是否是您的模型的另一個問題,或者說我沒有理解ASSIGNMENTS的實際用途。

+0

您在where子句中依賴隱式日期轉換。你應該使用to_date函數。 – 2012-02-14 23:38:00

+0

@MikeMcAllister - 實際上我只是'打斷'OP的代碼。我通常只會改變與手頭問題相關的內容。但我同意不使用日期函數可能會產生問題。 – APC 2012-02-15 09:59:29

+0

我考慮對OP的問題發表評論,但認爲這會引起誤解,因爲主要問題在其他地方。 – 2012-02-15 16:23:30