MYSQL-实现sqlserver- row_number() over(partit…
2018-06-18 00:47:17来源:未知 阅读 ()
sqlserver: with Result as ( select SUM(F_DayValue) AS F_Value,F_ZZ_ttBuildID,F_EnergyItemCode from T_EC_EnergyItemDayResult where F_EnergyItemCode like '%000' and F_StartDay>=@ldStartDate and F_StartDay<=@ldEndDate and F_ZZ_ttBuildID IN (select F_BuildID from T_BD_BuildBaseInfo) group by F_ZZ_ttBuildID,F_EnergyItemCode ) select a.F_Value,a.F_ZZ_ttBuildID,b.F_BuildName,a.F_EnergyItemCode, ROW_NUMBER() over(partition by a.F_EnergyItemCode order by a.F_Value desc) as nsort from Result a left join T_BD_BuildBaseInfo b on a.F_ZZ_ttBuildID=b.F_BuildID mysql: CREATE TEMPORARY TABLE IF NOT EXISTS Result ( select SUM(F_DayValue) AS F_Value,F_ZZ_ttBuildID,F_EnergyItemCode from T_EC_EnergyItemDayResult where F_EnergyItemCode like '%000' and F_StartDay>=V_ldStartDate and F_StartDay<=V_ldEndDate and F_ZZ_ttBuildID IN (select F_BuildID from T_BD_BuildBaseInfo) group by F_ZZ_ttBuildID,F_EnergyItemCode ); CREATE TEMPORARY TABLE IF NOT EXISTS TMP01 ( select a.F_Value,a.F_ZZ_ttBuildID,b.F_BuildName,a.F_EnergyItemCode from Result a left join T_BD_BuildBaseInfo b on a.F_ZZ_ttBuildID=b.F_BuildID ); select F_Value,F_ZZ_ttBuildID,F_BuildName,F_EnergyItemCode,nsort from ( select heyf_tmp.F_Value,heyf_tmp.F_ZZ_ttBuildID,heyf_tmp.F_BuildName,heyf_tmp.F_EnergyItemCode,@rownum :=@rownum+1 , if(@pdept=heyf_tmp.F_EnergyItemCode,@rank:=@rank+1,@rank:=1) as nsort, @pdept:=heyf_tmp.F_EnergyItemCode from ( select F_Value,F_ZZ_ttBuildID,F_BuildName,F_EnergyItemCode from TMP01 order by F_EnergyItemCode ASC ,F_Value desc ) heyf_tmp ,(select @rownum :=0 , @pdept := null ,@rank:=0) a) T;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:lnmp之mysql安装
下一篇:常用SQL语句集合
- PHP简单实现单点登录功能示例 2019-10-09
- thinkphp5框架前后端分离项目实现分页功能的方法分析 2019-10-08
- PHP7 安装event扩展的实现方法 2019-10-08
- php实现的数组转xml案例分析 2019-09-30
- PHP 使用 Swoole - TaskWorker 实现异步操作 Mysql 2019-09-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash