优化存储过程 ,帮忙 谢谢

wishY wishY 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

select Convert(nvarchar(2),d.CheckTime,101) as [month],
'bendi'=cast(cast(sum(case when p.CityID = 4 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'shanghai'=cast(cast(sum(case when p.CityID = 5 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'waidi'=cast(cast(sum(case when p.CityID = 6 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'haiwai'=cast(cast(sum(case when p.CityID = 9 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'waiguo'=cast(cast(sum(case when p.CountryID = 5 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'gangao'=cast(cast(sum(case when p.CityID = 7 or p.CityID = 8 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%'

from Peoples p inner join Country as c on p.CountryID = c.CountryID inner join Deals d on p.PeopleID = d.BuyID
inner join Houses h on h.HouseID=d.HouseID
where h.XiangMu like '%上海%' and d.CheckTime between '2007-1-1' and '2008-1-1' and h.FirstHandID = 1
group by Convert(nvarchar(2),d.CheckTime,101)

union all
select '合计' as [month],
'bendi'=cast(cast(sum(case when p.CityID = 4 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'shanghai'=cast(cast(sum(case when p.CityID = 5 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'waidi'=cast(cast(sum(case when p.CityID = 6 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'haiwai'=cast(cast(sum(case when p.CityID = 9 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'waiguo'=cast(cast(sum(case when p.CountryID = 5 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%',
'gangao'=cast(cast(sum(case when p.CityID = 7 or p.CityID = 8 then 1 else 0 end)*100.0/count(p.PeopleID) as int) as varchar)+'%'

from Peoples p inner join Country as c on p.CountryID = c.CountryID inner join Deals d on p.PeopleID = d.BuyID inner join Houses h on h.HouseID=d.HouseID
where h.XiangMu like '%上海%' and d.CheckTime between '2007-1-1' and '2008-1-1' and h.FirstHandID = 1
order by [month]

帮忙优化下,谢谢。
...全文

相关推荐

oracle 存储过程优化

作为一名数据库开发工程师必须掌握的技能,因为工作中会遇到很多需要优化的过程

yun12315

MySQL存储过程的优化实例

前言 在数据库的开发过程中,经常会遇到复杂的业务逻辑和对数据库的操作,这个时候就会用存储过程来封装数据库操作。如果项目的存储过程较多,书写又没有一定的规范,将会影响以后的系统维护困难和大存储过程逻辑的难以理解,另外如果数据库的数据量大或者项目对存储过程的性能要求很,就会遇到优化的问题,否则速度有可能很慢,经过亲身经验,一个经过优化过的存储过程要比一个性能差的存储过程的效率甚至高几百倍。下面介绍某一个MySQL存储过程优化的整个过程。 在本文中,需要被优化的存储过程如下: drop procedure if exists pr_dealtestnum; delimiter // create

weixin_38619467

ORACLE存储过程性能优化技巧

ORACLE存储过程性能优化技巧,帮助你更好的学习oracle的方方面面的技术!

zhanzh1985

ORACLE SQL 优化 存储过程 PROCEDURE

本人五年的SQL开发经验和存储过程开发样例、以及SQL优化要点,数据库DB_LINK,数据库审计等,绝对物超所值,欢迎大家下载。

jinlian0714

SQL存储过程优化参考

收藏的存储过程优化参考,包括: 存储过程编写经验和优化措施.doc 优化SQL语句和存储过程.pdf 希望对大家有点参考价值

zqliang
评论 17
收藏 已收藏
分享
返回顶部
wishY
MS-SQL Server 34,876 成员 254,635 内容