求sql查询语句的写法,,需要通过url获取到的城市id来反查省份的名字,如何写sql 10
求sql查询语句的写法,在统一个表下面,有城市和行政区域,如下图,因为需要,需要通过url获取到的城市id来反查省份的名字,如何写sql查询语句,谢谢!例如我们通过url...
求sql查询语句的写法,在统一个表下面,有城市和行政区域,如下图,因为需要,需要通过url获取到的城市id来反查省份的名字,如何写sql 查询语句,谢谢!例如我们通过url获取到id522 ,芙蓉区,如何查询出来521 长沙市,我现在写的select a.City,a.ID from KS_Province a where a.id=(select top 1 b.Parentid from KS_Province b where b.id=522),不管用,麻烦给帮忙解决,谢谢!
上面打错了字,是同一个表下面, 展开
上面打错了字,是同一个表下面, 展开
展开全部
select shname,shiname,name from table
inner join
(
(
select name as shname , left(code,2) as shcode from table
where right(code,4) = '0000'
)
inner join
(
select name as shiname , left(code,2) as shicode from table
where right(code,2) = '00'
and right(code,4) <> '0000'
)
on shcode = shicode
)
on left(code,2) = shcode
inner join
(
(
select name as shname , left(code,2) as shcode from table
where right(code,4) = '0000'
)
inner join
(
select name as shiname , left(code,2) as shicode from table
where right(code,2) = '00'
and right(code,4) <> '0000'
)
on shcode = shicode
)
on left(code,2) = shcode
追问
不好意思能否按我的字段写进去,你这样我看不太明白,sql懂的太少了,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询