From: | "shreedhar" <shreedhar(at)lucidindia(dot)net> |
---|---|
To: | "Postgre General" <pgsql-general(at)postgresql(dot)org> |
Subject: | Query Help |
Date: | 2003-03-29 07:42:50 |
Message-ID: | 004501c2f5c6$ccc53080$1201a8c0@a4005 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi All
SELECT TotalErrors.Year, TotalErrors.month, TotalReported, ClosedErrors, OpenErrors, FixedErrors FROM
( SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month, EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS TotalReported
FROM tblInformation
INNER JOIN tblError ON tblInformation.inforid = tblError.inforid
INNER JOIN tblErrorStatus ON tblErrorStatus.statusid = tblError.statusid
INNER JOIN tblJobInformation ON tblJobInformation.inforid = tblInformation.inforid
WHERE logdate >= '2002-01-01' AND logdate < now() AND tblJobInformation.projectid = 33
GROUP BY year, month ) AS TotalErrors
LEFT JOIN
( SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month , EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS ClosedErrors
FROM tblInformation
INNER JOIN tblError ON tblInformation.inforid = tblError.inforid
INNER JOIN tblErrorStatus ON tblErrorStatus.statusid = tblError.statusid
INNER JOIN tblJobInformation ON tblJobInformation.inforid = tblInformation.inforid
WHERE logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 2 AND tblJobInformation.projectid = 33
GROUP BY year, month ) As ClosedErrors
ON TotalErrors.month = ClosedErrors.month
LEFT JOIN
( SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month, EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS OpenErrors
FROM tblInformation
INNER JOIN tblError ON tblInformation.inforid = tblError.inforid
INNER JOIN tblErrorStatus ON tblErrorStatus.statusid = tblError.statusid
INNER JOIN tblJobInformation ON tblJobInformation.inforid = tblInformation.inforid
WHERE logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 6 AND tblJobInformation.projectid = 33
GROUP BY year, month ) AS OpenErrors
ON TotalErrors.month = OpenErrors.month
LEFT JOIN
( SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month, EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS FixedErrors
FROM tblInformation
INNER JOIN tblError ON tblInformation.inforid = tblError.inforid
INNER JOIN tblErrorStatus ON tblErrorStatus.statusid = tblError.statusid
INNER JOIN tblJobInformation ON tblJobInformation.inforid = tblInformation.inforid
WHERE logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 5 AND tblJobInformation.projectid = 33
GROUP BY year, month ) AS FixedErrors
ON TotalErrors.month = FixedErrors.month
ORDER BY TotalErrors.Year, TotalErrors.month
Using this query I am expecting result as
year month totalreported closederrors openerrors fixederrors
2002 1 31 29 2
2002 2 85 60 25
2002 3 16 12 4
2002 5 41 29 12
2002 7 48 48
2002 8 1 1
2002 10 51 51
2002 11 69 15 54
2002 12 8 8
2003 1 9 9
2003 2 38 38
But Retreiving result as
year month totalreported closederrors openerrors fixederrors
2002 1 31 29 2
2002 1 31 29 9
2002 2 85 60 25
2002 2 85 60 38
2002 3 16 12 4
2002 5 41 29 12
2002 7 48 48
2002 8 1 1
2002 10 51 51
2002 11 69 15 54
2002 12 8 8
2003 1 9 29 2
2003 1 9 29 9
2003 2 38 60 25
2003 2 38 60 38
I mean I values retreives across years data is repeating.
May I know how can I get expected results by above query.
Regards,
Sreedhar
From | Date | Subject | |
---|---|---|---|
Next Message | shreedhar | 2003-03-29 07:50:54 | Query |
Previous Message | Dann Corbit | 2003-03-29 06:54:44 | Re: Slow query needs a kick in the pants. |