Query Help - Mailing list pgsql-general
From | shreedhar |
---|---|
Subject | Query Help |
Date | |
Msg-id | 004501c2f5c6$ccc53080$1201a8c0@a4005 Whole thread Raw |
Responses |
Re: Query Help
|
List | 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 TotalReportedFROM
tblInformationINNER JOIN tblError
ON tblInformation.inforid = tblError.inforidINNER JOIN tblErrorStatus
ON tblErrorStatus.statusid = tblError.statusidINNER JOIN tblJobInformation
ON tblJobInformation.inforid = tblInformation.inforidWHERE
logdate >= '2002-01-01' AND logdate < now() AND tblJobInformation.projectid = 33GROUP
BY year, month ) AS TotalErrorsLEFT JOIN
(
SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month , EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS ClosedErrorsFROM
tblInformationINNER JOIN tblError
ON tblInformation.inforid = tblError.inforidINNER JOIN tblErrorStatus
ON tblErrorStatus.statusid = tblError.statusidINNER JOIN tblJobInformation
ON tblJobInformation.inforid = tblInformation.inforidWHERE
logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 2 AND tblJobInformation.projectid = 33GROUP
BY year, month ) As ClosedErrorsON
TotalErrors.month = ClosedErrors.monthLEFT JOIN
(
SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month, EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS OpenErrorsFROM
tblInformationINNER JOIN tblError
ON tblInformation.inforid = tblError.inforidINNER JOIN tblErrorStatus
ON tblErrorStatus.statusid = tblError.statusidINNER JOIN tblJobInformation
ON tblJobInformation.inforid = tblInformation.inforidWHERE
logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 6 AND tblJobInformation.projectid = 33GROUP
BY year, month ) AS OpenErrorsON
TotalErrors.month = OpenErrors.monthLEFT JOIN
(
SELECT DISTINCT EXTRACT( MON FROM logdate ) AS month, EXTRACT ( YEAR FROM logdate) AS year, COUNT(tblInformation.Inforid ) AS FixedErrorsFROM
tblInformationINNER JOIN tblError
ON tblInformation.inforid = tblError.inforidINNER JOIN tblErrorStatus
ON tblErrorStatus.statusid = tblError.statusidINNER JOIN tblJobInformation
ON tblJobInformation.inforid = tblInformation.inforidWHERE
logdate >= '2002-01-01' AND logdate < now() AND tblError.statusid = 5 AND tblJobInformation.projectid = 33GROUP
BY year, month ) AS FixedErrorsON
TotalErrors.month = FixedErrors.monthORDER
BY TotalErrors.Year, TotalErrors.monthUsing 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
pgsql-general by date: