MySQL如何将WHERE子句中未指定的值分组为“其他”?
我需要制作一份网站访问量的统计报告。在报告中,用户可以指定各种参数。到目前为止,每当他们为参数选择值时,就会添加一个额外的 WHERE 子句,如下所示:
SELECT id_browser, COUNT(visits)
FROM table
WHERE [...]
AND id_browser IN (1, 3, 6)
GROUP BY id_browser
但我真正需要做的是显示其余浏览器的统计信息,但我需要将它们分组为“其他”浏览器”。我该怎么做?
I need to produce a statistical report of the site visits. In the report users can specify various parameters. So far, whenever they select values for a parameter, an additional WHERE clause is added, like this:
SELECT id_browser, COUNT(visits)
FROM table
WHERE [...]
AND id_browser IN (1, 3, 6)
GROUP BY id_browser
But what I really need to do is to show the statistics for the remaining browsers as well, but I need to group them together as "other browsers". How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试以下:
Try below :
使用
CASE
语法:例如,
Use
CASE
syntax:e.g.,
您可以使用
UNION
合并结果,试试这个:
You can unite the results using
UNION
try this:
听起来这是一个简单的联合:
Sounds like it is a simple union: