选择BETWEEN列值 [英] Select BETWEEN column values

查看:97
本文介绍了选择BETWEEN列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将BETWEEN与列名而不是直接值一起使用,像这样:

I'm trying to use the BETWEEN with column names instead of direct values, something like this:

SELECT * FROM table WHERE column1 BETWEEN column2 AND column3;

这将返回类似17行的内容,但是如果我写:

This is returning something like 17 rows, but if i write:

SELECT * FROM table WHERE (column1 <= column2 AND column1 >= column3) OR (column1 >= column2 AND column1 <= column3)

我大约得到600行. 在这两种情况下,我只会得到column1值实际上是中间值的行,但是第二种方法给我更多的结果,因此第一种方法有问题.

i get around 600 rows.. In both cases i only get rows where column1 value is actually the middle value, but 2nd method gives me much more results, so 1st method has something wrong with it.

我怀疑问题可能出在使用带有列名而不是纯值的BETWEEN子句,并且SQL以某种方式将列名转换为实际值.这很奇怪,但是有人可以启发我吗? 谢谢

I suspect the problem might be on using BETWEEN clause with column names, instead of pure values, and somehow SQL is converting the column names to actual values..its strange, but can someone enlighten me please? Thanks

推荐答案

SELECT * FROM table WHERE column1 BETWEEN column2 AND column3; # gives 17 rows

SELECT * FROM table WHERE (column1 >= column2 AND column1 <= column3) # gives 17 rows

由于您的附加支票

(column1 <= column2 AND column1 >= column3)

已被OR编辑,您将获得其他行.

which is ORed, you get additional rows.

这篇关于选择BETWEEN列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆