Count errors and not display any less than a value
-
I have this query that works as it is. I want to modify it so that I do not see Alarm errors less than 50. I guess it would have to be a sub query to this; SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate FROM AlarmsList where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY' GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111) Thanks,
-
I have this query that works as it is. I want to modify it so that I do not see Alarm errors less than 50. I guess it would have to be a sub query to this; SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate FROM AlarmsList where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY' GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111) Thanks,
Try this:
SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate
FROM AlarmsList
where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY'
GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111)
HAVING COUNT(AlarmMessage) >= 50Adding the
HAVING
clause modifies the query so that only rows with an alarm message count >=50 are included in the output.Paul Marfleet
-
Try this:
SELECT WaysideName, ST, AlarmMessage, COUNT(AlarmMessage) AS Error_Count, CONVERT(char(10), EventDate, 111) as ErrorDate
FROM AlarmsList
where EventDate >@StartDate and EventDate 'OPERATIONAL AND HEALTHY'
GROUP BY WaysideName, ST, AlarmMessage, CONVERT(char(10), EventDate, 111)
HAVING COUNT(AlarmMessage) >= 50Adding the
HAVING
clause modifies the query so that only rows with an alarm message count >=50 are included in the output.Paul Marfleet
Thanks Paul. That did the trick. Boy was that simple!
-
Thanks Paul. That did the trick. Boy was that simple!
Thanks. The important thing to remember here is that the
WHERE
andHAVING
clauses provide different ways of filtering the output of a query. AWHERE
clause is used to filter non-aggregated data. AHAVING
clause is used in conjunction with aGROUP BY
clause to filter data aggregated in thatGROUP BY
clause.Paul Marfleet
-
Thanks. The important thing to remember here is that the
WHERE
andHAVING
clauses provide different ways of filtering the output of a query. AWHERE
clause is used to filter non-aggregated data. AHAVING
clause is used in conjunction with aGROUP BY
clause to filter data aggregated in thatGROUP BY
clause.Paul Marfleet
Thank You. It is always a good day when you learn something new! Regards, Brian