drfqfuhej48511519 2015-05-30 13:49
浏览 29
已采纳

我需要mysql查询来生成以下结果

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;

i want to total count impression,click,conversion. i want group by website url group by impression,group by click ,group by conversion. how to wright query? please help me i need to emergency !!!!! ![enter image description here][1]

I need following result

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--------------
  • 写回答

1条回答 默认 最新

  • douqiang3768 2015-05-30 13:54
    关注

    please try below query

    $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";
    

    Let me know this is the way you need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题