gpt4 book ai didi

sql - 使用 3 个不同的索引选择一系列行

转载 作者:行者123 更新时间:2023-11-29 05:46:21 25 4
gpt4 key购买 nike

我的数据库是这样的:

Book,Chapter,Verse,Scripture
"1","1","1","1text1"
"1","1","2","1text2"
"1","1","3","1text3"
"1","1","4","1text4"
"1","2","1","2text1"
"1","2","2","2text2"
"1","2","3","2text3"

我想选择从 1,1,1 到 1,2,3 的所有行。

但是我当前的查询不会返回第 1、1、4 行,因为 4 大于 3。

SELECT * FROM my_table WHERE 
Book >= 1 AND Book <= 1 AND
Chapter >= 1 AND Chapter <= 2 AND
Verse >= 1 AND Verse <= 3

最佳答案

MySQL 也支持 row constructors .如果您想要(例如)1 1:3 到 1 2:2,请使用:

SELECT * FROM bible
WHERE (1,1,3) <= (book, chapter, verse) AND (book, chapter, verse) <= (1,2,2)

对于 58 1:3 到 62 4:2,

SELECT * FROM bible
WHERE (58,1,3) <= (book, chapter, verse) AND (book, chapter, verse) <= (62,4,2)

将包括 58 1:4,59 1:1 和 60 10:10,但不包括 62 5:1。

我找不到太多文档,但 MySQL 遵循自 SQL-92 以来为行比较设置的行为。 (注意:链接是草案版本),特别是第 8.2 节“一般规则”7):

Let Rx and Ry be the two row value constructors of the comparison predicate and let Rxi and Ryi be the i-th row value constructor elements of Rx and Ry, respectively. "Rx [comp op] Ry" is true, false, or unknown as follows:
[...]
c) "Rx < Ry" is true if and only if Rxi = Ryi for all i < n and Rxn < Ryn for some n.

d) "Rx > Ry" is true if and only if Rxi = Ryi for all i < n and Rxn > Ryn for some n.

e) "Rx <= Ry" is true if and only if Rx = Ry or Rx < Ry.

f) "Rx >= Ry" is true if and only if Rx = Ry or Rx > Ry.

行比较在第 9.2 节中介绍,Joe Celko 的 SQL For Smarties (链接指向第 3 版,但同一主题存在于早期版本中)。

关于sql - 使用 3 个不同的索引选择一系列行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1365678/

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