sql子查询
2015-12-15 16:43
169 查看
--合同执行度(累计已审批/合同汇总金额)
--投资进度(合同汇总总额/批准概算投资额)
select a.*,cast(round((ljysp/( case when xmze=0 then 1 else xmze end))*100,2) as numeric(5,2)) as htzxd
,cast(round((( case when AP =0 then 0 else xmze/AP end))*100,2) as numeric(5,2)) as tzjd
,ROW_NUMBER() OVER (ORDER BY InfoId desc) AS RowIndex
from (
select
*,ISNULL((select Sum(HeaderMoney) from AgileCorp_Fund_PayApply where ProjectCode=Fund_vProject.ProjectCode),0)as ljysp,
ISNULL(( select sum((case when InitFactInputPrice>0 then InitFactInputPrice else ContractPrice end)) from AgileCorp_Fund_Contract where ProjectCode=Fund_vProject.ProjectCode),0)
as xmze
from Fund_vProject
)a
--投资进度(合同汇总总额/批准概算投资额)
select a.*,cast(round((ljysp/( case when xmze=0 then 1 else xmze end))*100,2) as numeric(5,2)) as htzxd
,cast(round((( case when AP =0 then 0 else xmze/AP end))*100,2) as numeric(5,2)) as tzjd
,ROW_NUMBER() OVER (ORDER BY InfoId desc) AS RowIndex
from (
select
*,ISNULL((select Sum(HeaderMoney) from AgileCorp_Fund_PayApply where ProjectCode=Fund_vProject.ProjectCode),0)as ljysp,
ISNULL(( select sum((case when InitFactInputPrice>0 then InitFactInputPrice else ContractPrice end)) from AgileCorp_Fund_Contract where ProjectCode=Fund_vProject.ProjectCode),0)
as xmze
from Fund_vProject
)a
相关文章推荐
- sqlserver排序规则&小数位精度不能自动截断的异常
- PostgreSQL学习笔记3之表的继承和分区
- SQL Server中left()函数,stuff()函数
- 常用的mysql语句
- PostgreSQL学习笔记2之模式
- redis持久化和常见故障
- PostgreSQL学习笔记1之表定义
- Redis的可视化工具的使用
- win7 64位安装redis 及Redis Desktop Manager使用
- 在 Mac OS X 上创建的 .NET 命令行程序访问数据库 (使用Entity Framework 7 )
- 安装redis 及 PHP redis 扩展
- Excel 表导入 SQL Server 2005
- SQL书写规范
- sql server 索引
- JDBC连接Oracle数据库时出现的ORA-12505错误及解决办法
- mysql表空间及索引大小的查看
- CentOS6上mongodb连接数无法突破1000的解决办法
- 问题:oracle select into;结果:oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解
- MySQL 必须调整的 10 项配置
- windows mysql 自动备份的几种方法