sql:在v1和v2之间 [英] sql: BETWEEN v1 AND v2
本文介绍了sql:在v1和v2之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SQL Server上的BETWEEN查询中,v1和v2的顺序是否有所不同?
Is there a difference in the order of v1 and v2 in a BETWEEN query on SQL Server?
SELECT *
FROM table
WHERE col BETWEEN v1 AND v2
当前,如果v1大于v2,我没有任何结果.这是唯一的语法糖吗?
currently I don’t get any results if v1 is bigger than v2. Is this only syntactic sugar for
col >= v1 AND col <= v2
还是真的需要两者之间的所有值?根据我目前的观察,我猜这是第一种情况.
or does it really take all values between the two? on my current observations I guess it’s the first case.
推荐答案
SQL Server 2008:
SQL Server 2008:
select 1
where 5 between 1 and 7
1个结果
select 1
where 5 between 7 and 1
0个结果
基于这些结果以及 Postgre文档我假设ANSI标准如下(尽管我找不到该文档).
Based on these results, and the Postgre Docs I would hypothesize that the ANSI Standard is as follows (although I can't find that doc).
a between x and y
==
a >= x AND a <= y
更新:
SQL-92规范说(引用):
The SQL-92 spec says (quote):
"X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z"
这篇关于sql:在v1和v2之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文