日期:2014-05-18  浏览次数:20319 次

主从表的显示问题,着急!!!
主表
                          a     b
                          c     d  
                  从表
                          a     ab     cd
                          a     dd     cc
                          c     aa     ll
两表进行关联要求显示成
                    显示数据
                      a         ab       cd
                                dd       cc
                      c         aa       ll

------解决方案--------------------
--其实可以不用主表,但最好增加一个唯一ID列

create table #t(id int identity(1,1), f1 varchar(100), F2 varchar(100), F3 varchar(100))

insert into #t
select 'a ', 'ab ', 'cd ' union all
select 'a ', 'dd ', 'cc ' union all
select 'c ', 'aa ', 'll '


--select * from #t

select
(case when id =(select min(ID) from #t where F1=A.F1) then F1 else ' ' end) as F1,
F2,
F3
from #t as A
order by ID

drop table #t
------解决方案--------------------
沙子叫星星,,,,,
我顶