with 子查询及递归的使用
```sqlcreate table t_area(id int,pid int,area varchar);insert into t_area values(1,null,'广东省');insert into t_area values(2,1,'深圳市');insert into t_area values(3,1,'东莞市');insert into t_area values(4,2,'南山区');insert into t_area values(5,2,'福田区');insert into t_area values(6,2,'罗湖区');insert into t_area values(7,3,'南城区');insert into t_area values(8,3,'东城区');
with 子查询
使用
with
子查询来选择 pid=1
的所有行:with t_gd_city AS (select * from t_area where pid=1)select * FROM t_gd_city;
查询结果:
id | pid | area |
2 | 1 | 深圳市 |
3 | 1 | 东莞市 |