日期:2014-05-16  浏览次数:21523 次

存储过程求解,有个变量怎么处理
table
id name number
1 fdfdfd 3223
2 dfdfdf 4566
存过程如下:
create procedure Ptest(in id int)
begin
select * from table where id=id;
end;//
此过程,就是依id号,显示信息,没有错语,我要改进一下。
安给的id来,称王筛选一下信息:
我要实现安name一列group by 应该怎么写
SQL code
create procedure Ptest2(in id int,in Paixu varchar(20))
begin
select * from table where id=id group by Paixu;
end;//


错在何处?
就是,那个变量要怎么处理
select * from table where id=id group by Paixu;
还是这样:
select * from table where id=id group by '.Paixu.';

------解决方案--------------------
1:你传入的PAIXU是字段的话,要用到动态SQL执行
2:用GROUP BY ,好好看看用法吧,感觉你用的是ORDER BY