我有一个名为ID(整数),N(整数)和V(真实)3列sqlite表。这一对(ID,N)是唯一的。在python sqlite3递归(级联)选择
使用Python模块sqlite3的,我想与形式
select ID from TABLE where N = 0 and V between ? and ? and ID in
(select ID from TABLE where N = 7 and V between ? and ? and ID in
(select ID from TABLE where N = 8 and V between ? and ? and ID in
(...)
)
)
我收到以下错误执行递归的选择,可能是因为最大递归深度超出(?)。我需要大约20到50 recusion水平
sqlite3.OperationalError: parser stack overflow
我也试图加入subselections像
select ID from
(select ID from TABLE where N = 0 and V between ? and ?)
join (select ID from TABLE where N = 7 and V between ? and ?) using (ID)
join (select ID from TABLE where N = 8 and V between ? and ?) using (ID)
join ...
但这种做法是supprisingly慢,即使有少数subselections
有没有更好的办法执行相同的选择?
注:该表索引的(N,V)
下面是显示选择如何运作
ID N V
0 0 0,1
0 1 0,2
0 2 0,3
1 0 0,5
1 1 0,6
1 2 0,7
2 0 0,8
2 1 0,9
2 2 1,2
步骤0
select ID from TABLE where N = 0 and V between 0 and 0,6
ID是在一个示例(0, 1)
步骤1
select ID from TABLE where N = 1 and V between 0 and 1 and ID in (0, 1)
ID仍处于(0,1)
步骤2
select ID from TABLE where N = 2 and V between 0,5 and 1 and ID in (0, 1)
ID为1
“V”边界在每一步都是一样的吗? “N”值来自哪里?你想要所有步骤中的ID吗? –
否每个步骤的V值都不相同。 N值是任意的,就这个例子而言。这个想法只是简单地逐步完善选择 – user2660966
典型的步骤是多少?你想要所有步骤中的ID吗? –