gpt4 book ai didi

mysql - 在表中,如何通过保留其他列的引用来选择一列的不同值?

转载 作者:行者123 更新时间:2023-11-29 15:47:36 25 4
gpt4 key购买 nike

在我的表中,我有 CategoryID 和 ProductName,这里 CategoryID 有重复的值。如何选择具有不同类别 ID 的 ProductName?

我尝试过看起来类似的堆栈溢出答案,但没有一个有帮助。

    +++++++++++++++  ++++++++++++++
+ ProductName + + CategoryID +
+++++++++++++++ ++++++++++++++
Mac 1
HP 3
Walker 1
Bell 2
Dell 4
Lenovo 3
Pixel 2

结果应该是

    +++++++++++++++  ++++++++++++++
+ ProductName + + CategoryID +
+++++++++++++++ ++++++++++++++
Mac 1
HP 3
Bell 2
Dell 4

最佳答案

您只需按categoryid分组并获取最小值(或最大值?)productname:

select categoryid, min(productname) as productname
from tablename
group by categoryid

关于mysql - 在表中,如何通过保留其他列的引用来选择一列的不同值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56951263/

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