请教:查询a表数据,显示省市区镇的名字,不显示id,并且分页,请问sql语句怎么写
oracle数据库a表opaIdnumber;opaNamevarchar;proIdvarchar2;cityIdvarchar2;disIdvarchar2;town...
oracle数据库
a表
opaId number;
opaName varchar;
proId varchar2;
cityId varchar2;
disId varchar2;
townId varchar2;
b表//省市区镇表
id number;
name varchar2;//省市区镇名字
proId number;
elevl number;
已经知道答案了,谢谢;
select * from (
select opaid,opaname,
(select b.name from b where b.id=a.proid),
(select b.name from b where b.id=a.cityid),
(select b.name from b where b.id=a.disid),
(select b.name from b where b.id=a.townid),
rownum r
from a where rownum<10
) where r>5 展开
a表
opaId number;
opaName varchar;
proId varchar2;
cityId varchar2;
disId varchar2;
townId varchar2;
b表//省市区镇表
id number;
name varchar2;//省市区镇名字
proId number;
elevl number;
已经知道答案了,谢谢;
select * from (
select opaid,opaname,
(select b.name from b where b.id=a.proid),
(select b.name from b where b.id=a.cityid),
(select b.name from b where b.id=a.disid),
(select b.name from b where b.id=a.townid),
rownum r
from a where rownum<10
) where r>5 展开
1个回答
展开全部
创建表及数据
create table t
(id int,
code int,
name varchar(20),
parentcode int)
insert into t values (1,10000,'浙江',0)
insert into t values (2,20000,'安徽',0)
insert into t values (3,11000,'杭州',10000)
insert into t values (4,12000,'宁波',10000)
insert into t values (5,21000,'合肥',20000)
insert into t values (6,22000,'宣城',20000)
insert into t values (7,11100,'萧山',11000)
insert into t values (8,11300,'滨江',11000)
insert into t values (9,11300,'富阳',11000)
执行
select t3.name1,t3.name2,t4.name from
(select t1.code code1,t1.name name1,t1.parentcode parentcode1,t2.code code2,t2.name name2,t2.parentcode parentcode2
from t t1 left join t t2 on t1.code=t2.parentcode where t1.parentcode=0) t3 left join t t4 on t3.code2=t4.parentcode
结果
以上sqlserver写法,其他数据库基本也差不多
create table t
(id int,
code int,
name varchar(20),
parentcode int)
insert into t values (1,10000,'浙江',0)
insert into t values (2,20000,'安徽',0)
insert into t values (3,11000,'杭州',10000)
insert into t values (4,12000,'宁波',10000)
insert into t values (5,21000,'合肥',20000)
insert into t values (6,22000,'宣城',20000)
insert into t values (7,11100,'萧山',11000)
insert into t values (8,11300,'滨江',11000)
insert into t values (9,11300,'富阳',11000)
执行
select t3.name1,t3.name2,t4.name from
(select t1.code code1,t1.name name1,t1.parentcode parentcode1,t2.code code2,t2.name name2,t2.parentcode parentcode2
from t t1 left join t t2 on t1.code=t2.parentcode where t1.parentcode=0) t3 left join t t4 on t3.code2=t4.parentcode
结果
以上sqlserver写法,其他数据库基本也差不多
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询