"Lucas Graf" <lgraf2000@comcast.net> wrote in message
news:uJYRRBNmGHA.4064@TK2MSFTNGP02.phx.gbl...
> Here is a link to the DDL since it would take up a lot of room here.
>
>
http://damageinc.org/DDL.html >
> After you use that to generate the table and some sample data, here is the
> problem I need help with.
>
> You will see the following data, if you use this query...
>
>
> SELECT DISTINCT Apps.AppName, TestCases.TestCase , Tests.Attributes,
> Reports.Result, Reports.ReportDate
> FROM
> Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
> LEFT OUTER JOIN Apps ON TestCases.AppID = Apps.AppID
>
> AppName TestCase Attribute Result
> ReportDate
> Test App 1 Run for 30 minutes Attribute 1 Fail
> 2006-06-25 19:58:31.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:29.800
> Test App 1 Run for 30 minutes Attribute 1 Pass
> 2006-06-25 19:58:30.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:33.800
> Test App 1 Run for 45 minutes Attribute 2 Fail
> 2006-06-25 19:58:34.800
> Test App 1 Run for 45 minutes Attribute 2 Pass
> 2006-06-25 19:58:32.800
> Test App 1 Run for 60 minutes Attribute 3 Fail
> 2006-06-25 19:58:36.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:35.863
> Test App 1 Run for 60 minutes Attribute 3 Pass
> 2006-06-25 19:58:37.863
>
>
> What I need to get is the count most recent result per TestCase regardless
> of attribute.
> So I was trying to do it visually by using this query..
>
> SELECT tc.TestCase, tc.mostRecent, tc.Result
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
>
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
>
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate ) ORDER BY TestCAse
>
>
> Which will give you this data...
>
> TestCase mostRecent Result
> Run for 30 minutes 2006-06-25 19:58:31.800 Fail
> Run for 30 minutes 2006-06-25 19:58:30.800 Pass
> Run for 45 minutes 2006-06-25 19:58:34.800 Fail
> Run for 45 minutes 2006-06-25 19:58:32.800 Pass
> Run for 60 minutes 2006-06-25 19:58:36.863 Fail
> Run for 60 minutes 2006-06-25 19:58:37.863 Pass
>
> Which as you can tell is giving me both the most recent pass & fail
> result, where I want the most recent result regardless of Pass/Fail.
>
> Which in turn, makes my count query wrong as well...
>
> SELECT COUNT(DISTINCT tc.TestCase) As Count,
> COUNT(DISTINCT CASE rp.Result WHEN 'Pass' THEN rp.ReportID ELSE NULL END)
> as Pass,
> COUNT(DISTINCT CASE rp.Result WHEN 'Fail' THEN rp.ReportID ELSE NULL END)
> as Fail
> FROM Reports rp
> RIGHT JOIN
> (
> SELECT TestCases.TestCase ,Reports.Result, MAX ( Reports.ReportDate ) AS
> mostRecent
> FROM Reports
> LEFT OUTER JOIN TestCases ON TestCases.TestCaseID = Reports.TestID
> LEFT OUTER JOIN Tests ON TestCases.TestCaseID = Tests.TestID
>
> WHERE ( (Tests.Attributes = 'Attribute 1') OR (Tests.Attributes =
> 'Attribute 2') OR (Tests.Attributes = 'Attribute 3') )
>
> GROUP BY TestCases.TestCase, Result) tc ON (tc.mostRecent =
> rp.ReportDate )
>
> Which will give me
>
>
> Count Pass Fail
> 3 3 3
>
>
> Instead of the result I am looking for of..
>
> Count Pass Fail
> 3 1 2
>
>
>