select a.t
from (select parent_type,parent_type as t from article
union all
select parent_type,' '+child_type as t from article ) a
order by a.parent_type
from (select parent_type,parent_type as t from article
union all
select parent_type,' '+child_type as t from article ) a
order by a.parent_type
from (select 1 as id,parent_type,parent_type as t from article
union all
select 2 as id,parent_type,' '+child_type as t from article ) a
order by a.parent_type,id
select a.t
from (select 1 as id,parent_type,parent_type as t from article
union all
select 2 as id,parent_type,' '+child_type as t from article ) a
order by a.parent_type,a.id
-------------------------------------------------------------------------------------------------------
.Net技术
.Net技术
.Net技术
Asp.Net基础
C#语言
VB.net语言
ASP技术
ASP技术
ASP技术
ASP基础
ASP应用
ASP技巧(所影响的行数为 12 行)
from (select 1 as id,aa.parent_type,aa.parent_type as t
from (select distinct prent_type from article ) aa
union all
select 2 as id,parent_type,' '+child_type as t from article ) a
order by a.parent_type,a.id
列名 'prent_type' 无效。
服务器: 消息 207,级别 16,状态 1,行 1
列名 'parent_type' 无效。
服务器: 消息 207,级别 16,状态 1,行 1
列名 'parent_type' 无效。
from (select 1 as id,aa.parent_type,aa.parent_type as t
from (select distinct parent_type from article ) aa --这里列名写错了
union all
select 2 as id,parent_type,' '+child_type as t from article ) a
order by a.parent_type,a.id
insert into #Type (id, mc) values (2, 'asp')
create table #book(id int, type nvarchar(10), bookname nvarchar(20))
insert into #book(id, type, bookname) values (1, '.net', 'C#1')
insert into #book(id, type, bookname) values (1, '.net', 'C#2')
insert into #book(id, type, bookname) values (1, '.net', 'C#3')
insert into #book(id, type, bookname) values (1, 'asp', 'asp1')
insert into #book(id, type, bookname) values (1, 'asp', 'asp2')select * from
(select 0 as xh,id, mc, '' as bookname, '' as id1, '' as type
from #type
union all
select 1, * from #book, #type
where #book.type = #Type.mc) a
order by mc, xhdrop table #Type
drop table #book在我的机器上测试通过
结果如下:
.Net技术 Asp.Net基础
.Net技术 C#语言
.Net技术 VB.net语言
ASP技术 ASP基础
ASP技术 ASP应用
ASP技术 ASP技巧
select a.t
from (select 1 as idd,article_type ,article_type as t from type
union all
select 2 as idd,parent_type,' '+child_type as t from article ) a
order by a.parent_type,a.idd
select a.t
from (select 1 as idd,article_type as parent_type,article_type as t from type
union all
select 2 as idd,parent_type,' '+child_type as t from article ) a
order by a.parent_type,a.idd