rt;
两张表没有关联。SELECT COUNT(DISTINCT ip) as ip,DATE_FORMAT(createtime,'%Y-%m-%d') as time from visit where year(createtime)
=2013 group by date(createtime) ORDER BY createtime DESC这样可以查询出一张表的每天的记录数。
还有一个activity表。
sql语句也是一样的,只是把ip字段换成name字段。
怎么能查出两张表每天的记录数呢?
试了很多方法都不行。请大神们给点思路,谢谢。

解决方案 »

  1.   

    SELECT COUNT(DISTINCT name) as ip,DATE_FORMAT(createtime,'%Y-%m-%d') as time from 
    (select ip as name,createtime from visit
    union all
    select name,createtime from activity
    )A
    where year(createtime)
    =2013 group by date(createtime) ORDER BY createtime DESC
      

  2.   

    SELECT COUNT(DISTINCT v.ip) as ip,COUNT(DISTINCT a.name) as name,DATE_FORMAT(v.createtime,'%Y-%m-%d') as time 
     from visit v LEFT OUTER JOIN activity a ON DATE_FORMAT(v.createtime,'%Y-%m-%d')=DATE_FORMAT(a.createtime,'%Y-%m-%d') 
    where year(v.createtime)=2013  group by date(a.createtime),date(v.createtime)
    ORDER BY v.createtime DESC————————————————————————————————————
    自己弄出来了... 谢谢各位