gpt4 book ai didi

sql - SQL在WHERE子句之后选择最小值

转载 作者:行者123 更新时间:2023-12-03 18:35:06 24 4
gpt4 key购买 nike

我是SQL的初学者,所以这很可能是一个非常简单的问题。我有一张包含邮资服务信息的表格,如下所示:

ID Service              Max_Weight Cost
----------------------------------------
1 SecondClassStandard 0.10 0.95

2 SecondClassStandard 0.25 1.19

3 SecondClassStandard 0.50 1.51

4 SecondClassStandard 0.75 2.05

5 SecondClassStandard 1.00 2.80


我如何执行以下查询(例如):

SELECT * FROM table WHERE Service = 'SecondClassStandard' AND Max_Weight >= 0.075;

然后从结果中获得一项可以满足体重要求的服务。换句话说,选择一个合适的结果-例如,从上面的查询中,它应该仅返回:

1|SecondClassStandard|0.10|0.95


但是,如果我要这样做:

SELECT * FROM table WHERE Service = 'SecondClassStandard' AND Max_Weight >= 0.105;

它应该返回:

2|SecondClassStandard|0.25|1.19

最佳答案

我想你打算像这样使用LIMIT子句

SELECT * FROM table 
WHERE Service = 'SecondClassStandard'
AND Max_Weight >= 0.075
LIMIT 1;

关于sql - SQL在WHERE子句之后选择最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30767847/

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