具有 ORDER、DISTINCT 和 COUNT 的 SQL 请求


SQL request with ORDER, DISTINCT and COUNT

我的表有4列:id,name,ip,timestamp

正在尝试获得如下结果:"向我显示每个"名称"的行数,其中包含不同的"ip"和非不同的 ip(总数)"

我使用此表来存储用户在某些链接上所做的所有点击,我想显示一个热门点击:对于每个"名称",点击的用户数量,以及此"名称"的总点击量。

这甚至可以在一个SQL请求中实现吗?

这样做:

select name
     , count(*) total_clicks
     , count(distinct ip) distinct_ppl
from table_name
group by name
order by name /* or by count(*) desc or count(distinct ip) desc */

您可以像这样获得前 10 个答题器:

SELECT count(ip),* FROM table GROUP BY ip ORDER BY count(ip) LIMIT 10;