0

我的问题是我使用查询,当我首先调用它时必须返回 N 个值,然后是下一个 N 个值等。此外,我还有一些排序类型,如按日期排序、按单词名称排序等、asc 和 desc 变体。在我使用按日期排序的地方,我可以使用类似 id>N 的东西(在我的代码中 a>3),即第一个 id 是 4,最后一个 id 是 9,然后在下一个查询中,首先是 10,最后一个 15 等等。但是该怎么办如果我需要按单词名称排序,我如何确定从哪个单词开始?

  select distinct s.a,w._word
  from (
        select a from edges 
        where a in 
        (
            select distinct w._id
            from edges as e 
            inner join words as w
            on w._id=e.a
            where w.lang_id=2
        ) and b in
        (
            select distinct w._id
            from edges as e 
            inner join words as w
            on w._id=e.b
            where w.lang_id=1
        )
        union
        select b from edges 

        where b in 
        (
            select distinct w._id
            from edges as e 
            inner join words as w
            on w._id=e.b
            where w.lang_id=2
        ) and a in
        (
            select distinct w._id
            from edges as e 
            inner join words as w
            on w._id=e.a
            where w.lang_id=1
        )
) as s
inner join words as w
on s.a=w._id 
inner join groups_set as gs
on w._id=gs.word_id
 where gs.group_id in (1,2,3) or w._word like '%d%' and a>3
order by w._word desc limit 5
4

1 回答 1

1

我问错了吗?LIMIT可以与偏移量一起使用。

要么喜欢

... LIMIT 5 OFFSET 5

或者

... LIMIT 5, 5

您不需要在查询中计算出偏移量,只需在应用程序中增加它。

有了这个,你也可以ORDER BY随心所欲。

于 2013-06-12T08:23:04.330 回答