我认为你不能只在 SQL 中做到这一点,这就是我在 PHP 中使用两个查询和一些 PHP 逻辑来构建第二个查询的方法。
//this array is to simulate your table, don't make it.
$data = [1 => '*****', 'This', 'is', 'data', '*****', '*****', 'more', 'data', '*****', 'random', '*****', 'rows', '*****'];
//Run a query to get all the ids
$sql = "SELECT id FROM tbl WHERE data = '*****' ORDER BY id ASC";
//assign them to an array - I did it manually.
$ids = [1, 5, 6, 9, 11, 13];
//Build the query to get the end sets.
$query = "SELECT * FROM tbl WHERE ";
while (count($ids)) {
$start = array_shift($ids);
$end = array_shift($ids);
$query .= "(id >= $start AND id <= $end) OR ";
}
$query = trim($query, " OR ");
echo $query;