mysql查询重复数据并计算每条重复数据count

来源:互联网 发布:淘宝钻展是什么意思 编辑:程序博客网 时间:2024/05/17 05:53

比如表base_keywords中有这样的数据:

id    apptype         keyword      count    up_time                    status    ip             num


1   keyword    thinkpad笔记本    10     2010-03-18 15:55:05     2       127.0.0.1     0

2   article        thinkpad笔记本    10     2010-03-18 15:55:05     2       127.0.0.1     0

3   product      thinkpad笔记本   11     2010-03-18 15:55:05     2       127.0.0.1     0

4   ariticle       thinkpad笔记本    12     2010-03-18 15:55:05     1       127.0.0.1    20

 

现在要查找aptype和keyword对应的数据,当然不能重复,而且要计算count的值,我的解决办法是:

 

SELECT apptype,keyword,SUM(count) AS count,MAX(up_time) AS up_time FROM base_keywords  GROUP BY apptype,keyword

 

这样得到的结果就是:

keyword    thinkpad笔记本    10     2010-03-18 15:55:05

article        thinkpad笔记本    22     2010-03-18 15:55:05

product      thinkpad笔记本   11     2010-03-18 15:55:05