select c.id,c.id from productclick as c left outer join 
productview as v on c.productid=v.productid and v.viewtype=1 and to_days(c.clickdate) = to_days('2009-7-10')
productclick 这个表是产品被点击的信息 productview是表被浏览的信息现在我想查出今天这个表被点击了多少次并且 是productview表中浏览类型viewtype=1的情况下点击的 这样的sql怎么写谢谢

解决方案 »

  1.   

    select c.id,count(*)
    from productclick as c left outer join productview as v 
    on c.productid=v.productid 
    where v.viewtype=1 and to_days(c.clickdate) = to_days('2009-7-10')
      

  2.   

    我试过这个查询出的数据不对,我的productclick里面只有8条数据
      

  3.   

    我试过这个查询出的数据不对,我的productclick里面只有8条数据,可是显示出30多条数据
      

  4.   

    建议能在贴子中把表结构,数据,期望的结果描述出来,这样获得解决方案的机会更多。参考一下个人觉得比较好的提问方式。得到回复的机率会大一些http://www.accessbbs.cn/bbs/viewthread.php?tid=19552
    http://www.accessbbs.cn/bbs/viewthread.php?tid=19546
      

  5.   

    http://topic.csdn.net/u/20090710/13/139b2179-3ddb-4e3a-99f7-754a6db3e51c.html
    看一下这个贴了浪费了多少时间在问题的表达上。
      

  6.   

    productclick 这个表是产品被点击的信息 productview是表被浏览的信息 
    productclick有8条记录 productview有2条记录
    为什么我用
    select * from productclick c,productview v where c.productid = v.productid
    查出16条记录呀下面是表结构
    CREATE TABLE `productclick` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `productid` int(11) NOT NULL,
      `clicknum` int(11) NOT NULL,
      `spent` decimal(13,2) DEFAULT NULL,
      `ipaddress` char(50) DEFAULT NULL,
      `refererurl` char(200) DEFAULT NULL,
      `active` int(11) DEFAULT NULL,
      `clickdate` datetime DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;CREATE TABLE `ad_bannerview` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `productid` int(11) DEFAULT NULL,
      `spent` decimal(13,2) DEFAULT NULL,
      `datestamp` char(50) DEFAULT NULL,
      `enterdate` datetime DEFAULT NULL,
      `viewtype` int(1) DEFAULT NULL,
      `keywords` char(100) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=99 DEFAULT CHARSET=utf8;
      

  7.   

    是否能提供一下你这 8 条 和 2 记录的内容?一来说如果 A,B两通过公有的 ID 字段相联的话A
    id
    1
    1
    1
    1B
    1
    1
    这样 from a,b where a.id=b.id 当然会产生 4*2 条记录。
    4
      

  8.   

    那怎么解决呀,我只想显示productclick中符合条件的记录