2012-02-13 36 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