How would I return TRUE or FALSE if four of the last six records failed for a given MAKEID? So there has to be 4 failures (or FALSE records) in the last six
MAKEID FAILURES CREATEDATE
101 TRUE 12/1/2015
101 FALSE 12/5/2015
101 TRUE 12/6/2015
101 FALSE 12/8/2015
101 TRUE 12/10/2015
101 FALSE 12/15/2015
101 FALSE 1/1/2016
101 FALSE 1/2/2016
102 TRUE 12/2/2015
102 TRUE 12/4/2015
102 FALSE 12/5/2015
102 TRUE 12/6/2015
102 FALSE 12/7/2015
102 TRUE 1/1/2016
Query would return the following:
MAKEID FOUROFLASTSIXFAILED
101 TRUE
102 FALSE
Requirement is there needs to be 4 or more failures in last six records. So if there were 4, 5, or 6 failures in the last six records FOUROFLASTSIXFAILED would return TRUE. If there were only 1, 2, 3 records for a given MAKEID that would return FALSE because there at least needs to be 4 failures in previous six records.
Best Answer
Here is one approach (but please, stop changing your requirements):
Results (I think these are right, as opposed to the desired output stated in your question, which seem to conflict with your stated requirements):
It would seem to me that
MAKEID = 102
is the only one that has failed exactly four times out of its last six entries, unless theFAILURES
column in the original table really representsNOT_FAILURES
.