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.   

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

  2.   

    第一:楼主你也不把错误信息贴出来
    第二:你的存储过程传递的参数有问题吧create procedure Ptest2(in id int,in Paixu varchar(20)),应该是这样的吧create procedure Ptest2(id  in int,Paixu  in varchar(20))
    第三:select * from table where id=id group by Paixu;不考虑Paixu是什么东西的话,也不能直接进行group by 分组;select Paixu,Count(*) from table where id=id group by Paixu;这个写法应该是对的
    第四:你查询以后没有将结果放到游标里面,存储过程也应该编译不过去
      

  3.   

    create procedure Ptest2(in id int,in Paixu varchar(20))-- 应该是( id in int,Paixu in varchar(20))-- 
    begin
    select * from table where id=id group by Paixu;
    end;//select * from table where id=id group by Paixu;--这里不能怎样写,要 select * into 变量 from table; 下来的group by Paixu 中Paixu 被当做字符串,不是栏位(只能想二楼说的那样使用动态语法),使用group by 的是要使用group by 函数(例如 count sum等)