gpt4 book ai didi

mysql - 选择组中的最高值

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

我有一个针对 mysql 数据库的选择查询,其中列出了许多项目的一系列值:

Bottle of single malt scotch,   £15
Bottle of single malt scotch, £1.00
Box of Deans shortbread, £2
Box of Deans shortbread, £1.00
Days fishing, £10
Days fishing, £1.00
Fishing reel, £5
Fishing reel, £1.00

查询是:

SELECT field7,field11 FROM 2007mod_mpform_results_249 ORDER BY field7,field11 DESC

我只想显示每个项目的最高值。这是一个简单的任务还是我需要进入子查询?我一直在寻找解决方案,但由于我是 SQL 新手,所以对结果感到非常困惑。

最佳答案

基本上你想选择它的名称和最高价格,所以你可以尝试这样的想法:

SELECT name, max(price) as price FROM products GROUP BY name ORDER BY name ASC

在这里,您可以选择名称并使用GROUP BY对结果进行分组。 max(price) 取该子组中的最高值。

关于mysql - 选择组中的最高值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29013357/

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