多条件运算时SQL的写法
来源:互联网 发布:相同网址不同域名 编辑:程序博客网 时间:2024/06/07 01:04
当需要基于不同条件产生的结果集上运算时,我们可以采用对单一结果集运算后,保持原有结果集,然后统一根据某个字段聚合后来求一些字段的和。
select A.port_no as port_no,
(select max(key_date) from dbo.TblHNWDate) as key_date,sum(A.pfd_shares) as tot_pfd_shares,
sum(A.par_value) as tot_par_value,
sum(A.cost) as tot_cost,
sum(A.adjusted_cost) as tot_adjusted_cost,
sum(A.market) as tot_market_value,
CASE
when (sum(A.market)-sum(A.adjusted_cost))>0 then ''
else 'N'
end
as tot_net_unrl_gl_s,
(sum(A.market)-sum(A.adjusted_cost)) as tot_net_unrl_gl
from
(
select
port.port_no as port_no,
case
when port.mod_secr_type='05' AND secr.class_code!='934' then port.quantity
else 0
end
as pfd_shares,
case
when port.mod_secr_type='05' AND secr.class_code!='934' then (port.quantity*secr.unit_cash_value)
when port.mod_secr_type='05' AND secr.class_code='934' then (port.quantity*secr.market_price_nuv)
when port.mod_secr_type!='05' then port.quantity
end
as par_value,
port.cost as cost,
port.adjusted_cost as adjusted_cost,
port.market as market
from TblHNWPort port,TblHNWSecr secr
where port.cusip = secr.cusip
and port.key_date = secr.key_date)A
group by A.port_no
- 多条件运算时SQL的写法
- queryDataSet中多条件过滤数据集的sql写法
- sql 语句 like 多个条件的写法
- 查询日期范围时SQL条件的写法
- 对于多个未知的的条件的sql语句的写法
- 必须知道的SQL编写技巧,多条件查询不拼字符串的写法
- 自己总结的不定条件SQL查询语句的写法
- 多条件搜索,sql语句,决对经典的拼接写法
- mysql where 条件中的字段有NULL值时的sql语句写法
- mysql where 条件中的字段有NULL值时的sql语句写法
- ibatis里面sql语句中条件使用like的写法
- 多条件匹配的精简写法
- MDX多条件同时满足的写法
- 检索条件的写法
- 分区使用本地索引时,SQL注意条件写法
- mybatis动态sql在and条件中嵌套or条件的写法。
- Mybatis动态sql条件查询中if判断Integer的条件写法
- for循环中有多个限制结束条件的正确写法(小心逗号运算符)
- Oracle Databases : Oracle CBO 学习笔记之(1) : 深入理解Oracle Hash Join的代价模型及其执行流程
- 二叉树的遍历
- WebSphere遗忘管理控制台密码
- 虚基类,指向基类的指针,待删除
- 九度oj1006zoj问题
- 多条件运算时SQL的写法
- 新版MapReduce的API编程简单模板
- Junit4使用方法
- POJ2451Uyuw's Concert
- HDU 1162
- 关于C中可变参数的记录
- shell实现旋转线
- poco在qnx上编译(附网上找的在iphone上编译)
- 命令行打印某个程序的socket信息