MySQL Select 从返回的id结果中排除m

MySQL Select From To And Exclude m in returned id result

我有 SQL return 来自 MySQL:

SELECT id, channel, (y.count) AS channels
FROM (
    SELECT s.id AS id, c.sort, s.channel
    FROM channels c, streams s
    LEFT JOIN logo l ON s.id=l.channel
    WHERE JSON_SEARCH(s.bouquet, 'one', 1) IS NOT NULL 
    AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL
    AND JSON_SEARCH(c.sort, 'one', s.id) IS NOT NULL

    UNION 

    SELECT m.marker, c.sort, m.channel
    FROM markers m, channels c, streams s
    LEFT JOIN logo l ON s.id=l.channel
    WHERE JSON_SEARCH(m.bouquet, 'one', 1) IS NOT NULL 
    AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL
    AND JSON_SEARCH(c.sort, 'one', m.marker) IS NOT NULL
    AND s.id=l.channel) ch
CROSS JOIN (
    SELECT count
    FROM (
        SELECT COUNT(s.id RLIKE '^[0-9]+$') AS count
        FROM streams s, channels c 
        WHERE JSON_SEARCH(s.bouquet, 'one', 1) IS NOT NULL 
        AND JSON_SEARCH(c.bouquet, 'one', 1) IS NOT NULL 
        AND JSON_SEARCH(c.sort, 'one', s.id) IS NOT NULL) AS x) AS y
ORDER BY LOCATE(CONCAT('"', id, '"'), sort);

Return 从这个查询是:

+----+-------------------+
| id | channel           |
+----+-------------------+
| m2 | AA-AA             |
| 1  | KR_A 1            |
| 2  | KR_A 2            |
| 11 | HR_A 3            |
| 12 | HR_B 1            |
| m4 | BB-BB             |
| m3 | CC-CC             |
| 17 | SR_B 1            |
| m5 | DD-DD             |
| m1 | EE-EE             |
+----+-------------------+

我需要修改 SQL 到当我在查询中添加 m2 到 return:

1
2
11
12

如果我添加 m3 我需要得到:

17

所以我尝试在 SQL 的开头添加这个来过滤 id:

SELECT IF (id BETWEEN 'm2' AND '%m', id, 0) As id, channel, (y.count) AS channels

我明白了:

+----+-------------------+----------+
| id | channel           | channels |
+----+-------------------+----------+
| m2 | AA-AA             |        5 |
| 0  | KR_A 1            |        5 |
| 0  | KR_A 2            |        5 |
| 0  | HR_A 3            |        5 |
| 0  | HR_B 1            |        5 |
| m4 | BB-BB             |        5 |
| m3 | CC-CC             |        5 |
| 0  | SR_B 1            |        5 |
| m5 | DD-DD             |        5 |
| m1 | EE-EE             |        5 |
+----+-------------------+----------+

并且需要得到这个:

+----+-------------------+----------+
| id | channel           | channels |
+----+-------------------+----------+
| 1  | KR_A 1            |        4 |
| 2  | KR_A 2            |        4 |
| 11 | HR_A 3            |        4 |
| 12 | HR_B 1            |        4 |
+----+-------------------+----------+

我不知道如何在 SQL 查询 select 从 'm2' 到下一个 'm' 并排除 'm2''m' 结果....有什么帮助吗?

如果前一行是所需的标记(当 id 以 'm' 开头时)或者如果 id 在所需标记之后(当 id 不是以 'm' 开头并且标志 (@showRow) 处于活动状态时)

SET @showRow:=0;
SELECT id, channel, (y.count) AS channels...
...
 WHERE 
     (
       @showRow:=( (id like 'm%' and id = 'm2') or (id not like 'm%' and @showRow ) )
      )
   -- ommit marker row
   AND id not like 'm%'
;