多条件运算时SQL的写法
多条件运算时SQL的写法
当需要基于不同条件产生的结果集上运算时,我们可以采用对单一结果集运算后,保持原有结果集,然后统一根据某个字段聚合后来求一些字段的和。
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
>更多相关文章
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 05-15奇安信:数据安全问题是医疗卫生行业数字化
- 05-15腾讯宣布混元文生图大模型开源
- 05-15网易云音乐与韩国知名娱乐公司Kakao达成战略
- 05-15阿联酋宣告正式开启“5G-A全国商用”计划,
- 05-15二十年未遇的强烈地磁暴来袭
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御