Mysql 查询某个分级下面所有的子分级【存储器】

Mybatis:

 SELECT id
        FROM (
                 SELECT @r AS _ids,
( SELECT @r := GROUP_CONCAT( id ) FROM stock.stock_area WHERE FIND_IN_SET( stock_area.parent_id, @r ) ) AS subIds
                 FROM
                     ( SELECT @r := #{area} ) vars,
                     stock.stock_area
                 WHERE
                     @r IS NOT NULL
             ) sub,
             stock.stock_area
        WHERE FIND_IN_SET(stock_area.id, sub._ids)

Mysql:

SELECT id
 FROM (
 SELECT @r AS _ids, (
 SELECT @r := GROUP_CONCAT( id )
 FROM stock.stock_area
 WHERE FIND_IN_SET( stock_area.parent_id, @r ) ) AS subIds
 FROM (
 SELECT @r := '31' ) vars, stock.stock_area
 WHERE @r IS NOT NULL ) sub, stock.stock_area
 WHERE FIND_IN_SET(stock_area.id, sub._ids);

你可能感兴趣的:(mysql,数据库)