SELECT N rows before and after the row matching the condition?

前端 未结 6 1835
暗喜
暗喜 2021-02-02 15:02

The behaviour I want to replicate is like grep with -A and -B flags . eg grep -A 2 -B 2 \"hello\" myfile.txt will give me all the lines wh

6条回答
  •  情书的邮戳
    2021-02-02 15:47

    Try

    Select * from theTable
    Where id >=
    (Select id - variableHere from theTable where message like '%hello%')
    Order by id
    Limit (variableHere * 2) + 1
    

提交回复
热议问题