ruby on rails - Counting rows in SQL with multiple AND & OR statements -
ruby on rails - Counting rows in SQL with multiple AND & OR statements -
i'm trying count number of rows in database date range in created , if 1 of several zip codes. semantically i'm trying count complaints these zip codes during period of time. query looks this,
select count(*) complaints created_date::date >= '2013-10-03' , created_date::date <= '2014-05-31' , incident_zip = 11209 or incident_zip = 11201 or incident_zip = 11202;
i can't seem query run without or
statement making and
statements meaningless. explain how grouping or
statement affects incident_zip column , not created_date column?
in case there's no need multiple clauses containing incident_zip
. instead, grouping them using in
clause:
select count(*) complaints created_date::date >= '2013-10-03' , created_date::date <= '2014-05-31' , incident_zip in (11209, 11201, 11202);
ruby-on-rails database postgresql where
Comments
Post a Comment