postgresql - PostgresSQL - Loop through daily Select statement for end of month reporting -
postgresql 9.4.5 the following select statement run every night @ 11:55 pm. want run monthly query (or function) loops through following query based on hard-coded start_date , end_date. query must process results on day-by-day basis. want see how many lost sheep have in given month. purpose: lost sheep- looking users attempt login mysoftware , unsuccessful entire day. *the ip address compared against other login attempts may successful rest of day. in event of login failure, query should ip address , verify no successful logins happened same ip address within day. select distinct l.username, l.ip login l l.ip not in (select l.ip login l date_trunc('day', l."time") = current_date , l.succeeded = 'true') , date_trunc('day'...