select sum() from tb1 into @a ,这种语句为何报错呢?但是加上 where 就不报错。
select sum(f2) 
from tb1
where 1=1   -- 为何这里没有这一句,就会报错呢?
into @a;
select @a;
drop table if exists tb1;CREATE TABLE `tb1` (
  `f1` int(11) DEFAULT NULL,
  
`f2` decimal(18,2) DEFAULT NULL
) ;-- go
insert into tb1 values(1,89.67),(2,67.34),(3,88.12);select *
from tb1;
select sum(f2) 
from tb1
where 1=1   -- 为何这里没有这一句,就会报错呢?
into @a;
select @a;

解决方案 »

  1.   

    正规的语法应该是select sum()  into @a  from tb1MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  2.   

    select sum() from tb1 into @a---没有指定sum函数中的参数,也就是列,select sum(f2) into @a from tbl;和select sum(f2) from tb1 into @a 应该都可以。自己试试就知道了。
      

  3.   


    select sum() from tb1 into @a 这种格式
      

  4.   


    你太有意思了,sum()是简写呀,我偷懒,我以为大家会明白的。
    我总不至于连 sum() 必须有参数也不知道呀。你的回复,我刚明白是什么意思