sql时间示例频率

ivqmmu1c  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(361)

我试图输出工作人员登录的频率,因此我有两个表。
表1:工人

+----------+
| workerid |
+----------+
| w1       |
| w2       |
| w3       |
| w4       |
+----------+

表2:信息

+----------+-----------+
| workerid | timestamp |
+----------+-----------+
| w1       |  23494944 |
| w1       |  24444444 |
| w3       |  26773735 |
| w4       |  86433333 |
+----------+-----------+

查询的预期输出:

+------------------+----------------+
| count of workers | number_entries |
+------------------+----------------+
|                1 |              2 |
|                2 |              1 |
+------------------+----------------+

我写了这个,但我不知道如何定义时间的频率。

SELECT COUNT(DISTINCT(Worker_id)) as  count_of_workers, COUNT(FREQUENCY) as number_entries
GROUP BY user id
ORDER BY COUNT desc;
shstlldc

shstlldc1#

如果我理解正确的话,你想要两个 group by 学生:

select num_entries, count(*) as num_workers
from (select worker_id, count(*) as num_entries
      from information
      group by worker_id
     ) i
group by num_entries
order by num_entries;

相关问题