Mysql join two tables with counpe oft the different type of records -


i'm having 2 table sendmail , campaign tables in mysql. sendmail table represents both sent , failed status in stats field. , campaign filed having campaign table id reference. i'm trying display how many mails had been sent , failed in each campaign. 2 table structure are, sendmail tableenter image description here

campaign table structure enter image description here , expected result:

campaigname        totalsent totalunsend  aaaa               0          1 supply chain       6          0 development        6          0 design&development 8          3 

you can use query this:

select   campaign.name,   sum(status=1) totalsent,   sum(status=0) totalunsent   campaign inner join sendmail   on campaign.campaignid = sendmail.campaignid group   campaign.name 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -