目前我有一个页面在左侧和右侧使用 php 和 SQLite 显示 2 个图像。
使用给定的图像 ID 我查询
- 该图像的文件
- 下一张图片的文件
- 下一张图片的链接
- prev-prev-image 的链接
- 到 prev-image 的链接(如果 prev-prev 不存在)
我尝试过使用偏移量,但是如果我的偏移量超出范围,似乎整个查询都会失败,有什么方法可以防止或捕获它吗?
select id, file, findex
from vfb
where findex > (select findex from vfb where findex<4 and bookcode='BEFB'
order by findex desc limit 1 offset 1)
and findex < (select findex from vfb where findex>4 and bookcode='BEFB'
order by findex asc limit 1 offset 1)
and bookcode='BEFB'
order by findex asc;
现在我使用的select(select a where x<1) as a1, (select a where x=1) as b1, (select b where x=1) as c1
结构非常丑陋,结果我现在需要来自查询的更多信息,例如 ( select a where x<1
)。
那么,有没有办法缩短我的查询或使用类似的东西(select a,b where x<1) as a1,b2
?
我的桌子就像Id|bookcode|page|findex(fakepage)|file|title|stuff|morestuff
全丑选择:
select
(select findex from vfb where bookcode='BOOK' and findex<
(select findex from vfb where bookcode='BOOK' and findex<100 order by findex desc limit 1) order by findex desc limit 1) as p2,
(select findex from vfb where bookcode='BOOK' and findex<100 order by findex desc limit 1) as p1,
(select file from vfb where bookcode='BOOK' and findex==100) as f1,
(select file from vfb where bookcode='BOOK' and findex>100 order by findex asc limit 1) as f2,
(select findex from vfb where bookcode='BOOK' and findex>
(select findex from vfb where bookcode='BOOK' and findex>100 order by findex asc limit 1) order by findex asc limit 1) as n2;
结果是:
98|99|BOOK_Page_104_Image_0001.png|BOOK_Page_105_Image_0001.png|102
我尝试过使用偏移量,但是如果我的偏移量超出范围,似乎整个查询都会失败,有没有办法阻止或捕获它?