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怎么写谢谢
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怎么写谢谢
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')
http://www.accessbbs.cn/bbs/viewthread.php?tid=19546
看一下这个贴了浪费了多少时间在问题的表达上。
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;
id
1
1
1
1B
1
1
这样 from a,b where a.id=b.id 当然会产生 4*2 条记录。
4