zoukankan      html  css  js  c++  java
  • 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少很多的代码,如果你有更简单的方法可以给我发个地址,我也是新手.

  • 相关阅读:
    poj2421 Constructing Roads *
    poj1789 Truck History *
    关于最小生成树的一些理解
    资源收集【更新】
    poj2313 Sequence ***
    poj1258 AgriNet **
    最大流的算法小结 Algorithm for Maximum Flow
    算法导论18.32 BTREEDELETE的伪代码
    poj2325 Persistent Numbers ****
    23天的单车旅行,从广州到四川,篇首语
  • 原文地址:https://www.cnblogs.com/xiaoliao/p/3624191.html
Copyright © 2011-2022 走看看