gpt4 book ai didi

Mysql select查询按通配符分组

转载 作者:行者123 更新时间:2023-11-29 06:08:25 27 4
gpt4 key购买 nike

无法通过通配符对活跃论坛总结果进行分组。

最终,我希望将具有相似名称的所有结果分组并汇总到不同的行中。

表格:论坛

栏目:游戏、帖子

当前查询:

SELECT game, sum(posts) FROM forums WHERE posts>1 AND game like
'%rift%' OR game like '%swiftsure%' GROUP BY name

当前结果:

Game posts

Rift (PVP Defiant): Briarcliff 3406

Rift Guides 100

Rift Leadership 1541

Rift Raid Discussion 1336

Rift Raid Leadership 533

Rift: Cleric 85

Rift: Mage 87

Rift: Private 411

Rift: PVE Leadership 113

Rift: Rogue 56

Rift: Warrior 29

Star Wars The Old Republic PvP - Swiftsure 7

SWTOR Swiftsure Leadership 0

SWTOR: Swiftsure Private 7

期望的结果如下所示:

Game | posts

Rift | 7697

Swiftsure | 14

我当然感谢任何和所有的帮助!

最佳答案

由于您正在寻找通用分组,因此我会做一个 CASE/WHEN 作为列...

SELECT case when game like '%rift%'      then 'Rift   '
when game like '%swiftsure%' then 'Swiftsure'
end as GroupName,
count(*) as PostCount
from
forums
where
game like '%rift%'
OR game like '%swiftsure%'
GROUP BY
GroupName

关于Mysql select查询按通配符分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10387047/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com