本帖最后由 coolria 于 2009-11-13 19:54:02 编辑

解决方案 »

  1.   

    select a.userid,count(b.time) as counter from a left join b on a.userid=b.id and b.time='2009-01-02' group by a.userid;
      

  2.   

    mysql> select * from a;
    +--------+------+
    | userid | name |
    +--------+------+
    |      1 | abc  |
    |      2 | cde  |
    |      3 | hig  |
    |      4 | lim  |
    +--------+------+
    4 rows in set (0.00 sec)mysql> select * from b;
    +----+------------+
    | id | time       |
    +----+------------+
    |  1 | 2009-01-02 |
    |  1 | 2009-01-02 |
    |  1 | 2009-03-01 |
    |  2 | 2009-01-02 |
    |  2 | 2009-03-05 |
    +----+------------+
    5 rows in set (0.00 sec)mysql> select a.userid,count(b.time) as counter from a left join b on a.userid=b.id and b.time='2009-01-02' group by a.userid;
    +--------+---------+
    | userid | counter |
    +--------+---------+
    |      1 |       2 |
    |      2 |       1 |
    |      3 |       0 |
    |      4 |       0 |
    +--------+---------+
    4 rows in set (0.01 sec)