当前位置: 代码迷 >> Sql Server >> 求一SQL查询,困扰好多天了,该如何解决
  详细解决方案

求一SQL查询,困扰好多天了,该如何解决

热度:67   发布时间:2016-04-27 18:43:51.0
求一SQL查询,困扰好多天了
@a=sum(t1.c1)
@b=sum(CASE WHEN t2.d= 1 
THEN t2.e
ELSE t2.e/100 * @a)
t1.f=t2.f
求@a-@b的SQL,大虾帮忙啊,小弟感激不尽

------解决方案--------------------
select @[email protected]
------解决方案--------------------
把表给出来
------解决方案--------------------
SQL code
select    @a=sum(t1.c1),    @b=sum(CASE WHEN t2.d= 1 THEN t2.e ELSE t2.e/100 [email protected] end),    @[email protected]from    t1,t2where     t1.f=t2.f
------解决方案--------------------
SQL code
declare @a as intselect @a = sum(t1.c1) from t1declare @b as intselect @b = sum(CASE WHEN t2.d = 1 THEN t2.e ELSE t2.e/100 * @a) from t1 , t2 where t1.f=t2.f select @a - @b
------解决方案--------------------
SQL code
declare @a decimal(10,2),@b decimal(10,2)select @a=sum(c1) from t1select @b=sum(CASE WHEN t2.d= 1 THEN t2.e ELSE t2.e/100 * @a end) from t1,t2 where t1.f=t2.fselect @[email protected]
------解决方案--------------------
我在4楼的是返回一个值.
------解决方案--------------------
sum只返回1行阿,你没有group,返回什么列
------解决方案--------------------
关注,学习!
------解决方案--------------------
看不懂
------解决方案--------------------
..
------解决方案--------------------
..
  相关解决方案