时间:2021-07-01 10:21:17 帮助过:3人阅读
s
1,表结构:city_info
2,实体类
3,sql:
方法一:关联查询
select ci1.id,(select ci2.name from city_info ci2 where ci2.id = ci1.pId) as pName,ci1.name,ci1.title,ci1.type from city_info ci1;
方法二:左外连接查询
select ci1.id,ci2.name pName,ci1.name,ci1.title,ci1.type from city_info ci1 LEFT JOIN city_info ci2 ON ci1.pId = ci2.id;
4,查询结果
sql自关联查询上级id对应的名字
标签:join 查询 http mic 结构 src 图片 height nbsp