List:General Discussion« Previous MessageNext Message »
From:b Date:July 8 2009 7:55pm
Subject:Re: COUNT from 2 tables
View as plain text  
On 07/08/2009 03:33 PM, Gary Smith wrote:
> Off the top of my head, try this.
>
> SELECT
> MONTHNAME(s.created) AS month,
> sum(if(ifnull(s.id,0)>  0, 1, 0)) AS num_logins,
> sim(if(ifnull(d.id, 0)>  0, 1, 0)) AS num_downloads
> FROM sessions AS s LEFT JOIN downloads AS d
> ON d.session_id = s.id GROUP BY month
>

Nope, I'm still getting those same incorrect sums. Thanks, though. It 
seems to me that the problem is that I'm grouping by the month for one 
table but counting from both.

I'd paste the output here but I just upgraded Fedora and the BETA (wtf?) 
version of Thunderbird crashes when I paste into an email (how the 
earlier paste worked I don't know).
Thread
COUNT from 2 tablesb8 Jul
  • RE: COUNT from 2 tablesGary Smith8 Jul
    • Re: COUNT from 2 tablesb8 Jul
      • RE: COUNT from 2 tablesGary Smith9 Jul
        • Re: COUNT from 2 tablesb9 Jul
  • Replication switch Master to slave and backBryan Cantwell8 Jul
    • Re: Replication switch Master to slave and backAaron Blew8 Jul
      • Re: Replication switch Master to slave and backMarcus Bointon8 Jul