字段间求和问题

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,

我想再定义一个字段,为这三个字段的和,该怎么写
...全文
71 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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 的回复:]
引用 5 楼 wellcc 的回复:
对啊,这也行,关键是我就想用已经查好的那三个啊
没必要再浪费资源了
[/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,211

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧