gpt4 book ai didi

sql - SQL Server 中的 BETWEEN

转载 作者:行者123 更新时间:2023-12-03 01:24:10 25 4
gpt4 key购买 nike

如何获得 4 到 8 之间的数字。我想要的答案是 5,6,7,但在 SQL Server 中使用时脚本返回 4,5,6,7,8:

SELECT * 
FROM table
WHERE numbers BETWEEN '4' AND '8'

最佳答案

BETWEEN 包含在内。来自 MSDN:

BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.

由于它是包容性的,因此您将需要使用大于和小于:

SELECT * 
FROM yourtable
WHERE numbers > 4
AND numbers < 8

参见SQL Fiddle with Demo

如果您想使用 BETWEEN 运算符,那么您需要缩短范围:

SELECT * 
FROM yourtable
WHERE numbers between 5 AND 7

参见SQL Fiddle with Demo

关于sql - SQL Server 中的 BETWEEN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12387587/

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