以下是引用卜酷塔在2006-2-27 12:13:00的发言:
应该加几个括弧把!
楼主看看下面这个语句如何啊?
declare @my_sum int
select @my_sum =(select my_sum=sum(my_sum) from mytable2 )
select a.my_name,b.my_sum
from mytable1 as a,mytable2 as b
where left(my_date,6)='200506'
where (left(my_date,6)='200506' )
and (a.my_id=b.my_id )
and (@my_sum >90)
卜酷塔的思路应该是没有错的只是 应该把那个总值赋给变量的句子修改一下
declare @my_sum int
select my_id,my_sum=sum(my_sum) into mytable3 from mytable2 where left(my_date,6)='200506' group by my_id
select a.my_name,b.my_sum
from mytable1 as a,mytable3 as b
where (a.my_id=b.my_id )
and (@my_sum >90)