小编Niy*_*tel的帖子

当行数超过特定计数时对行进行分组

询问:

select city.name as name, sum(count) as views from profpostview
inner join professional as prof on prof.pfid = profpostview.viewerpfid
left join cityinfo as city on city.cityid = prof.cityid
where pfpid = _pfpid group by name order by views desc;
Run Code Online (Sandbox Code Playgroud)

输出:

**name , views**

'Ahmedabad', '14'
'Gandhinagar', '7'
'Mumbai', '5'
'Aalborg', '5'
'Rajkot', '3'
'Bhavnagar', '2'
'Baroda', '1'
Run Code Online (Sandbox Code Playgroud)

必需的:

**name, views**

'Ahmedabad', '14'
'Gandhinagar', '7'
'Aalborg', '5'
'others', '11
Run Code Online (Sandbox Code Playgroud)

解释:当行数超过 3 时,我想通过添加视图数来合并行。 Profpostview 表通过 pfpid 与 profpostinfo 相关联,而 profpostinfo 表又通过 cityid …

mysql

3
推荐指数
1
解决办法
153
查看次数

标签 统计

mysql ×1