我写了一个语句:select d_name as '区县',乡镇,普查区,普查小区 from dress,(select d_name as '乡镇',普查区,普查小区,d_pid as pid from dress,(select num as '普查小区',d_name as '普查区',d_pid as pid from pcxq,dress where pcxq.code=dress.d_code) as pcqwhere dress.d_id=pcq.pid) as xzwhere dress.d_id=xz.pid 感觉可能复杂了,求高手指点。
2 回答
九州编程
TA贡献1785条经验 获得超4个赞
1、用连接要结构清晰些,不需要那么多子查询。
2、你的d_code存储得很有规范,不一定需要用d_pid关联。
SELECT 区县=t4.d_name,乡镇=t3.d_name,普查区=t2_dname,普查小区=t1.num FROM pcxq t1LEFT JOIN dress t2 ON t2.d_code=t1.codeLEFT JOIN dress t3 ON t3.d_code=LEFT(t1.code,9)LEFT JOIN dress t4 ON t4.d_code=LEFT(t1.code,6)
- 2 回答
- 0 关注
- 802 浏览
添加回答
举报
0/150
提交
取消