日魂月魄

导航

MSSQL N张表关联查询

 

本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址

https://www.baiydu.com

 

  declare @newTime varchar(50);

 declare @lasetTime varchar(50);  

set @newTime= getdate();

 set @lasetTime= STUFF(sUBSTRING(@newTime,1,5),3,1,'');

       select * from (select * from(select B.Name,B.Id,B.Price,B.Term,B.Value,C.LoginName  from (select * from(SELECT top(5) Yuanbo_Target.Name,  Yuanbo_TargetRecord.Id,Yuanbo_TargetRecord.Account, Yuanbo_TargetRecord.Term, Yuanbo_TargetRecord.Value,Yuanbo_TargetRecord.Price FROM Yuanbo_Target INNER JOIN Yuanbo_TargetRecord ON Yuanbo_Target.Id= Yuanbo_TargetRecord.Target and Yuanbo_TargetRecord.CalculateCatalog=19 and Term like '%'+@lasetTime+'%' ORDER BY Yuanbo_TargetRecord.Id desc) A   group by A.Id,A.Name,A.Account,A.Price,A.Term,A.Value )B inner join Member_Account C on   C.Id=B.Account)D  group by D.Id,D.Name,D.LoginName,D.Price,D.Term,D.Value ) E inner join Member_Expert F on E.Id=F.Id  order by(E.Id)

 

select * from (select * from 这就是核心,以前用三张表关联的情况较少,当时用的方法 也是from sheet1,sheet2,sheet3要多些很多打很多字母。。。呵呵  当前工作遇到的数据库很烂,所以下午研究了下关联查询。。。。。。核心就是  select * from (select * from select * from (select * from select * from (select * from记得了呵呵,不过暂时还没测试这中方式是否效率,不过我敢保证这样的规律可以实现N张表关联查询,不管你有多复杂,而且比sheet1,sheet2,sheet3少很多的代码,如果你有更简单的方法可以给我发个地址,我也是新手.

posted on 2014-03-25 21:32  L-H  阅读(609)  评论(0编辑  收藏  举报