sql 联合查询速度慢,需要对其进行分组

分组:
SELECT   * FROM(
SELECT ROW_NUMBER() OVER(ORDER BY  ProjID) as row_number,* FROM (

select

ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
,min(ConSignDate) as ConSignDate,max(ConBalanceDate) as ConBalanceDate  
from 
dbo.fn_GetProjectsByUserId(100093) as p INNER join (select
cog.ConProjId,cog.ConSignDate,cog.ConBalanceDate from dbo.Dat_Contract
as cog  group by cog.ConProjId,cog.ConSignDate,cog.ConBalanceDate ) as
co
on   co.ConProjId=p.ProjID   and ConSignDate<=‘2015-09-22‘
and  ISNULL(ProjIsDeleted,0)!=1  group by
ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
)as t1

) as tt where row_number between 1 and 5

---耗时0.01

SELECT   * FROM(
SELECT ROW_NUMBER() OVER(ORDER BY  ProjID) as row_number,* FROM (

select

ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
,min(ConSignDate) as ConSignDate,max(ConBalanceDate) as ConBalanceDate  
from  dbo.fn_GetProjectsByUserId(100093) as p INNER join dbo.Dat_Contract as co
on  
co.ConProjId=p.ProjID   and ConSignDate<=‘2015-09-22‘ and 
ISNULL(ProjIsDeleted,0)!=1  group by
ProjApplyDate,projProperty,ProjID,ProjStatusCurrent,ProjGuId,ProjEtpId,ProjRegionId,ProjName,ProjAddress,ProjAreaSize,ProjCost,ProjCreateTime,ProjChargePerson,ProjChargePersonPhone,ProjApplyEtp,ProjApplyPerson,ProjApplyPersonPhone,ProjConstructEtp,ProjConstructPM,ProjConstructPMPhone,ProjDirector,ProjDirectorPhone,ProjSafeOrgz,ProjCode,ProjIsEnable
)as t1

) as tt where row_number between 1 and 5

--耗时 0.18

时间: 2024-10-01 22:08:48

sql 联合查询速度慢,需要对其进行分组的相关文章

SQL 联合查询 + XML解析

(select a.EBILLNO, a.EMPNAME, a.APPLYDATE, b.HS_NAME, replace(replace(a.SUMMARY,char(10), ''),char(13),'') as SUMMARY, cast(c.XmlData as XML).value('(/List/item/No/text())[1]','NVARCHAR(300)') as No, cast(c.XmlData as XML).value('(/List/item/zje/text

数据库sql联合查询mid类型的分页数据取不了全部的值错误

USE [Travel]GO/****** Object:  StoredProcedure [dbo].[NoticeGetPagedData]    Script Date: 06/13/2014 20:44:51 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[NoticeGetPagedData]@pageIndex int = 1,--页码@pageSize int =10,--页容量

SQL联合查询(内联、左联、右联、全联)语法

SQL联合查询(内联.左联.右联.全联)语法 概述: 联合查询效率较高,举例子来说明联合查询:内联inner join .左联left outer join .右联right outer join  .全联full outer join 的好处及用法. 联合查询效率较高,以下例子来说明联合查询(内联.左联.右联.全联)的好处: T1表结构            (用户名,密码) userid(int) username            varchar(20) password       

SQL联合查询:子表任一记录与主表联合查询

今天有网友群里提了这样一个关于SQL联合查询的需求: 一.有热心网友的方案: 二.我的方案: select * from ( select a.*,(select top 1 Id from B as b where b.CgId =a.ID)as bid from A as a ) as temp left join B as b2 on temp.bid=b2.Id

对sql server查询速度的优化

处理百万级以上的数据提高查询速度的方法: 1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 3.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如:     select id from t where num is null     可以在num上设置默认值0,确保表中num列没有

SQL联合查询中的关键语法(转)

联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用户名,密码)    userid int         username   varchar(20)     password       varchar(20) 1                    jack                           jackpwd 2                    owen                        owenpwd t3表结构(用户积分,等级)    u

SQL联合查询中的关键语法

联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用户名,密码)    userid int         username   varchar(20)     password       varchar(20) 1                    jack                           jackpwd 2                    owen                        owenpwd t3表结构(用户积分,等级)    u

SQL联合查询

[原文链接] http://www.cnblogs.com/aaapeng/archive/2010/01/20/1652151.html#commentform 联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用户名,密码)    userid int         username   varchar(20)     password       varchar(20) 1                    jack                           ja

hibernate用sql联合查询数据库

@RequestMapping(value = "/FeedPager.cqzk")     @ResponseBody     public String url_sa1(HttpServletRequest request, BootPage page)             throws ServletException, IOException, RuntimeException {         @SuppressWarnings("unchecked"