CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`form_id` tinyint(4) NOT NULL COMMENT '1=shortfor;2=longfom',
`remote_addr` varchar(19) NOT NULL,
`type` tinyint(4) NOT NULL COMMENT '1=impression;2=click;3=conversion',
`website_url` varchar(50) NOT NULL,
`c_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `form_id` (`form_id` , `remote_addr` , `type` , `website_url`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=64;
我想总计算展示次数,点击次数,转化次数。 我希望通过网站按网址分组按组,按组点击,按转换分组。 如何怀疑查询?请帮帮我,我需要紧急!!!!! ![在此输入图像说明] [1]
我需要以下结果
website url----------Impression----click--converison-----
192.1.1.1--------------1-----------2------1--------------
192.1.1.2--------------3-----------2------2--------------
192.1.1.3--------------4-----------3------1--------------
192.1.1.4--------------2-----------6------1--------------
答案 0 :(得分:3)
请尝试以下查询
$sql = "SELECT website_url,SUM(type=1) as impression,SUM(type=2) as click,SUM(type=3) as conversion FROM `test` GROUP BY website_url";
让我知道这是你需要的方式。