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', l."time") = current_date                         , l.succeeded = 'false'   fields in table logins  1. id  -int  2. username --character varying(255)  3. ip -- character varying (255)  4. time -- timestamp without time zone  5. succeeded -- boolean 

select date_trunc('day', l.time) 'day', l.username, l.ip login l date_trunc('month', l.time) = '2015-09-01' group 1, 2, 3 having not bool_or(succeded) 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -