gpt4 book ai didi

mysql - SQL Group-By 最频繁

转载 作者:行者123 更新时间:2023-11-29 04:34:32 25 4
gpt4 key购买 nike

<分区>

假设我有下表

+-----------------------+----------------+
| PERSON | ATE |
+-----------------------+----------------+
| Joe | Chicken |
| Joe | Chicken |
| Joe | Chicken |
| Joe | Tuna |
| Joe | Tuna |
| Joe | Chicken |
| Joe | Tuna |
| Joe | Chicken |
| Joe | Tuna |
| Joe | Tuna |
| Joe | Tuna |
| Joe | Chicken |
| Joe | Tuna |
| Joe | Tuna |
| Joe | Chicken |
| Joe | Tuna |
| Joe | Tuna |
| Joe | Tuna |
| Rob | Chicken |
| Rob | Tuna |
| Rob | Chicken |
| Rob | Chicken |
| Rob | Chicken |
| Rob | Chicken |
| Jonathan | Tuna |
| Jonathan | Tuna |
| Jonathan | Chicken |
| Jonathan | Tuna |
| Jonathan | Chicken |
+-----------------------+----------------+

我想找出每个人最常吃的食物。因此,期望的结果将是:

+-----------------------+----------------+
| PERSON | ATE |
+-----------------------+----------------+
| Joe | Tuna |
| Rob | Chicken |
| Jonathan | Tuna |
+-----------------------+----------------+

自然地,我会 GROUP BY (Person)。之后,我必须找到每组中最常吃的东西。如果它们是数字,那会很容易,因为我可以只使用 MAX 函数,但我不知道如何从一堆中挑选出最受欢迎的字符串。

您将如何完成我在 SQL 中尝试做的事情?

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