如何显示MySQL中最常见的值序列?

发布于 2024-11-07 21:58:57 字数 326 浏览 5 评论 0原文

假设我有一张这样的桌子。

A | B
-----
1 | 4
7 | 8
1 | 3
1 | 2
4 | 5
3 | 5
2 | 5
7 | 8

尽管 1A 列中最常见的值,而 5B 列中最常见的值(可以使用 COUNT() 非常简单地检查),我正在寻找的结果是 <7, 8> 对,因为该对出现了两次。

那么如何从表中获取最常见的值序列,因为我需要使用 n 列来执行此操作。

Lets say I have a table like this.

A | B
-----
1 | 4
7 | 8
1 | 3
1 | 2
4 | 5
3 | 5
2 | 5
7 | 8

Even though 1 is the most common value in column A and 5 is the most common value in column B (which can be checked pretty simply with a COUNT()) the result I am looking for is the pair <7, 8> since that pair appears twice.

So how can I get the most common value sequence from a table, since I have n columns that I need to do this with.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此岸叶落 2024-11-14 21:58:57
select A, B, count(*) as freq
from MyTable
group by A, B
order by count(*) desc
limit 1
select A, B, count(*) as freq
from MyTable
group by A, B
order by count(*) desc
limit 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文