mysql - Count entries from different tables per day -


i have 2 tables:

reports:     date, uuid warns:     date, uuid, active 

where date timestamp (2016-05-16 16:06:58), uuid user-identifier string , active boolean.

i want display how many reports , warns entries there per day. have query:

select date(date) date, count(*) reports reports group date(date) order date(date) desc 

which displays table this:

date       | reports  -----------+--------- 2016-07-05 | 192      2016-07-04 | 230      2016-07-03 | 227      

but want join in how many warns entries occurred day if it's active column true, want query return table this:

date       | reports | warns -----------+---------+------- 2016-07-05 | 192     | 47 2016-07-04 | 230     | 59 2016-07-03 | 227     | 56 

i newbie @ mysql haven't been able figure out how yet. searched bit on joins , unions didn't know if/how applied case. appreciated.

you can use correlated query:

select date(reports.date) date, count(*) reports,        (select count(*) warns         date(warns.date) = date(reports.date) , warns.active = 'true') warns_cnt reports group date(reports.date) order date(reports.date) desc 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -