table1                            table2  
id    firstTime                   usid         lastTime  
1     2007-5-1                    1            2007-5-2 00:5:01 
2     2007-5-1                    2            2007-5-2 05:06:12 
3     2007-5-2                    3            2007-5-6 12:01:15 
4     2007-5-3                    4            2007-6-2 15:11:12 
5     2007-5-3                    5            2007-5-8 00:00:05 
6     2007-5-4  
7     2007-6-1  
8     2007-6-2  
9     2007-6-2 
我希望得到的结果是这样的 
time          count(firstTime)        count(lastTime) 
2007-5-1        2                        0 
2007-5-2        1                        2 
2007-5-3        2                        0 
2007-5-4        1                        0 
2007-5-5        0                        0
2007-5-6        0                        0
2007-5-7        0                        0
2007-5-8        0                        0
...........
........... 
2007-6-2        2  
感激不尽....

解决方案 »

  1.   

    你的time是连续的吗?
    select * from (
    (select firsttime,count(firsttime) as count from table1 group by firsttime)
    as a
    left join (select lastTime ,count(lastTime ) as count from table2 group by lastTime ) as b 
    on a.firsttime=b.lasttime
     
    ) as temp 
      

  2.   

    table1的时间字段只有年月日..而table1的时间字段有年月日还有小时分钟秒
      

  3.   

    如果time不连续的话,需要一个date表,table2有分钟秒,这个没有关系,转换一下就行了。
      

  4.   

    共同期待yangxiao_jiang的正解哈!
      

  5.   

    不知道对不对
    select t1.firstTime as time, count(t.firstTime) as 'count(firstTime)' ,count(t2.lastTime) as 'count
    (lastTime)'
    from table1 as t1,table2 as t2
    group by t1.firstTime;
      

  6.   

    本帖最后由 yueliangdao0608 于 2007-10-14 08:13:30 编辑