本文介绍了大于表达式中的 SQL 多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看到以下与游标分页结果相关的 SQL,但无法找到有关其工作原理的更多信息:
Saw the following SQL relating to paging results with cursors and am having trouble finding more information on how part of it works:
SELECT b.* FROM books b
WHERE (b.name, id) > (select b2.name, b2.id
from books b2
where b2.id = ?
)
ORDER BY b.name;
当您在一个比较表达式中有多个列时会发生什么?我还没有找到任何其他的例子.
What happens when you have multiple columns within a single comparison expression? I haven't found any other examples of this.
推荐答案
比较是作为元组"从左到右进行的.因此,在每个元组中比较第一个值,然后比较下一个值.所以:
The comparisons are made as "tuples", from left to right. So, the first value is compared in each tuple, then the next is compared. So:
- (1, 2) >(1, 1) --> 正确
- (1, 1) >(1, 1) --> 假
- (2, 1) >(2, 2) --> 假
- (2, 1) >(1, 10) --> 真
(1, 2) > (1, 1)
--> true(1, 1) > (1, 1)
--> false(2, 1) > (2, 2)
--> false(2, 1) > (1, 10)
--> true
这篇关于大于表达式中的 SQL 多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!