MySQL: Joining select counts from same table

Tags:
MySQL
Please I want to join the statements below to get a single output
Select count(*) TotalAccounts,Affiliate from realdb.tbl_logs group by affiliate

Select count(*) TotalGen,Affiliate from realdb.tbl_logs where lastdate =curdate() group by affiliate

Select count(*) TotalNotGen,Affiliate from realdb.tbl_logs where lastdate <>curdate() group by affiliate


Software/Hardware used:
running this in mysql
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

This should work:

select count(*) TotalAccounts,Affiliate, 
    sum(if(lastdate = curdate(),1,0)) TotalGen, 
    sum(if(lastdate = curdate(),0,1)) TotalNotGen, 
from realdb.tbl_logs
group by affiliate;

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: