简体   繁体   English

从mysql中包含字符串的列初始化偏移量

[英]Initializing offset from column containing string in mysql

I want to get the data after the row with a certain string.我想在具有特定字符串的行之后获取数据。 I think I will explain it better with the following example.我想我会用下面的例子更好地解释它。 Below is a mysql table.下面是一个mysql表。

-id- -name(unique)-
 1    Test 
 2    Test2
 3    Test3
 4    Test4

Here, for example, I want to get the data after the row with the name 'Test2'.例如,在这里,我想获取名称为“Test2”的行之后的数据。 Is it possible to do this in one query with mysql?是否可以使用 mysql 在一个查询中执行此操作? (By pulling the id of the row with that data and not using it as an offset.) (通过使用该数据提取行的 id 而不是将其用作偏移量。)

It should give the following result as a result.它应该给出以下结果。

-id- -name-
 3    Test3
 4    Test4

I searched but couldn't find it or I couldn't understand how to search.我搜索但找不到它,或者我不明白如何搜索。 Can you help?你能帮我吗?

You basically need to use LIMIT and OFFSET .您基本上需要使用LIMITOFFSET Since you don't know the number of rows you want to have in you result, you can set limit to a high number.由于您不知道要在结果中包含的行数,因此您可以将限制设置为较大的数字。 Something like就像是

SELECT 
* 
FROM 
TABLE1 t 
LIMIT 9999999999 
OFFSET 2

OFFSET value can be set to whatever number of rows you want to exclude from your result. OFFSET 值可以设置为要从结果中排除的任何行数。

Or as per your question if you don't want to use OFFSET , use a subquery to determine the id或者根据您的问题,如果您不想使用OFFSET ,请使用子查询来确定 id

SELECT 
* 
FROM 
TABLE1 t 
WHERE 
t.id>(SELECT t1.id FROM TABLE1 t1 WHERE t1.name='Test2')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM