求sql语句(mysql)

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:07:19
RX
求(在某个time里,js_id出现最多的)
比如time=1026,js_id=11

js_id time
11 1026
12 1026
11 1026
11 1026
13 1025

select js_id,max(total) from
(select js_id,count(*) as total from table
where time between .. and ..) test

什么意思?

select js_id,max(countid ) from (select js_id,count(js_id) as countid form table where time=1026)

select s_id,time,count(*) ACount from 表 group by s_id,time having count(*)=max(ACount)

思路
使用count()进行分组统计,统计结构按从大到小排序,使用top 1取第一个就行。