# 字段间求和问题

wellcc 2009-03-16 07:00:02
``````isnull((select  sum( gxe )   From   cwkj_gxe  where convert(varchar(7),yearmonth,120)  =convert(varchar(7),M_zjl_sp.yearmonth,120)  and fyxm_jt_lm = 'sc-ry_gz'),0) as sc_hxe_ry_gz,
isnull((select  sum( gxe )   From   cwkj_gxe  where convert(varchar(7),yearmonth,120)  =convert(varchar(7),M_zjl_sp.yearmonth,120)  and fyxm_jt_lm = 'sc-ry_fl'),0) as sc_hxe_ry_fl,
isnull((select  sum( gxe )   From   cwkj_gxe  where convert(varchar(7),yearmonth,120)  =convert(varchar(7),M_zjl_sp.yearmonth,120)  and fyxm_jt_lm = 'sc-ry_tx'),0) as sc_hxe_ry_tx,``````

...全文
66 10 打赏 收藏 转发到动态 举报

10 条回复

wellcc 2009-03-16
• 打赏
• 举报

[Quote=引用 1 楼 sdhdy 的回复:]
SQL code--这样写，用in
isnull((select sum( gxe ) From cwkj_gxe where convert(varchar(7),yearmonth,120) =convert(varchar(7),M_zjl_sp.yearmonth,120) and fyxm_jt_lm in('sc-ry_tx','sc-ry_gz','sc-ry_fl'),0) as asdf ,
[/Quote]

``````
isnull((select  sum( gxe )   From   cwkj_gxe  where convert(varchar(7),yearmonth,120)  =convert(varchar(7),M_zjl_sp.yearmonth,120)  and fyxm_jt_lm in('sc-ry_tx','sc-ry_gz','sc-ry_fl')),0) as asdf ,

``````
wellcc 2009-03-16
• 打赏
• 举报

[Quote=引用 6 楼 htl258 的回复:]

[/Quote]

wellcc 2009-03-16
• 打赏
• 举报

htl258_Tony 2009-03-16
• 打赏
• 举报

[Quote=引用 5 楼 wellcc 的回复:]

[/Quote]没必要再浪费资源了
wellcc 2009-03-16
• 打赏
• 举报

SQLUCK 2009-03-16
• 打赏
• 举报

select *,sc_hxe_ry_gz+sc_hxe_ry_fl+sc_hxe_ry_tx as ww from(你这一堆) as t

htl258_Tony 2009-03-16
• 打赏
• 举报

wellcc 2009-03-16
• 打赏
• 举报

sdhdy 2009-03-16
• 打赏
• 举报

``````--这样写，用in
isnull((select  sum( gxe )   From   cwkj_gxe  where convert(varchar(7),yearmonth,120)  =convert(varchar(7),M_zjl_sp.yearmonth,120)  and fyxm_jt_lm in('sc-ry_tx','sc-ry_gz','sc-ry_fl'),0) as asdf ,
``````

22,181

• 近7日
• 近30日
• 至今