计算SQL中单击的链接,总数和唯一数

时间:2014-05-13 20:43:03

标签: mysql sql

我正在简单的表中收集点击次数

user_id | count | meta
=====================================
  1     |   3   | http://google.com
  1     |   2   | http://twitter.com
  2     |   1   | http://google.com
  3     |   2   | http://example.com
  4     |   1   | http://google.com

现在我想知道

  • 点击了多少用户(至少一次 - 唯一)
  • 用户点击任意链接的频率(总计)

输出应该是

uniq | total
=============
 4   |   9  

目前我有

SELECT COUNT(DISTINCT count) AS uniq, SUM(count) AS total FROM my_table

但结果是三个唯一身份用户

sqlfiddle

1 个答案:

答案 0 :(得分:2)

您需要计算用户数:

SELECT COUNT(DISTINCT user_id) AS uniq, SUM(count) AS total
----------------------^
FROM my_table;
相关问题