SELECT b.Name+'-------'+a.Name FROM TB as a inner join (select id,Name from TB where ParentId=0) as b on a.ParentId=b.id ;这个可以
CREATE TABLE [dbo].[Test](
[编号] [int] NULL,
[母号] [int] NULL,
[名字] [varchar](50) NULL
) ON [PRIMARY]
insert Test(编号,母号,名字) values ('1','0','中国')
insert Test(编号,母号,名字) values ('2','0','美国')
insert Test(编号,母号,名字) values ('3','1','北京')
insert Test(编号,母号,名字) values ('4','1','上海')
insert Test(编号,母号,名字) values ('5','2','华盛顿')
insert Test(编号,母号,名字) values ('6','2','纽约')
select a.名字 + '-' + b.名字 from test a
join test b on a.编号 = b.母号
没看出这种组合的依据。
就是查出的结果是 国家+城市
SELECT b.Name+'-------'+a.Name FROM [DFAUCTION].[dbo].[tbCar_Source] as a inner join (select id,Name from [DFAUCTION].[dbo].[tbCar_Source] where ParentId=0) as b on a.ParentId=b.id ;
with cte1 as (select * from dbo.Category_Info where CateID IN (SELECT CateID FROM dbo.Category_Info WHERE ParentID=0)
union all select a.* from Category_Info a inner join cte1 b on a.ParentID=b.CateID ) select NT.*,pt.CateName from cte1 NT join Category_Info PT on NT.parentid=PT.CateID
看起来不行
这个貌似不是那么回事啊
@路旭辉: 怎么不行?
@路旭辉:
@饥饿定义我:
SELECT b.Name+'-------'+a.Name FROM TB as a inner join (select id,Name from TB where ParentId=0) as b on a.ParentId=b.id ;这个可以
select (select mingzi from Table_1 where bianhao = a.muhao and muhao='0' ) + '-' + mingzi from table_1 a where muhao<>'0'
貌似只能查出来2条
select c1.name+'-'+c2.name
from city c1
join city c2 on c1.id = c2.parentid
SELECT b.Name+'-------'+a.Name FROM [DFAUCTION].[dbo].[tbCar_Source] as a inner join (select id,Name from [DFAUCTION].[dbo].[tbCar_Source] where ParentId=0) as b on a.ParentId=b.id ;