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

  • 相关阅读:
    CPU问题导致的大量进程崩溃问题
    coredump的裁剪方法
    GDB中遍历art::Thread打印local reference的脚本
    jemalloc管理块(arena、bin)
    jemalloc存储块(region、run、chunk)
    GDB中打印pthread_internal_t的方法
    FUSE引起的SIGBUS问题分析报告
    GDB中打印ART基础类
    UC浏览器闪退问题分析报告
    『深度实战』天池小目标检测大赛·宫颈癌风险智能诊断推荐
  • 原文地址:https://www.cnblogs.com/xiaoliao/p/3624191.html
Copyright © 2011-2022 走看看