Re: limit based on count(*) - Mailing list pgsql-general

From Russell Keane
Subject Re: limit based on count(*)
Date
Msg-id 8D0E5D045E36124A8F1DDDB463D548557D1618F4D3@mxsvr1.is.inps.co.uk
Whole thread Raw
In response to limit based on count(*)  (Steve Clark <sclark@netwolves.com>)
List pgsql-general
> Hello List,
>
> I have a query that counts how many time an event occurs in our event_log=
 these are grouped by the serial number of the device that created the even=
t. I would like to show only the rows where the number of events exceeds so=
me threshold.
>
> simplified query:
> select serial_no, count(*) as "restarts" from event_log where event_mesg =
ilike 'system sta%' and event_date > current_date - 7 group by serial_no or=
der by restarts;
>
> So what I would like to see is only the serial_nos that had more than X r=
estarts.
>
> Any ideas would be appreciated.
>
> --
> Stephen Clark

Could you not do:

Select * from=20
(
select serial_no, count(*) as "restarts" from event_log where event_mesg il=
ike 'system sta%' and event_date > current_date - 7 group by serial_no orde=
r by restarts
)
Where "restarts" > X;

Regards,

Russell Keane
INPS

Follow us on twitter | visit www.inps.co.uk

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: limit based on count(*)
Next
From: Maz Mohammadi
Date:
Subject: Re: confirming security.