mysql 儲存過程 動態排序
//引數
set @sidx=sx;/排序名稱/
set @sord=sd;/排序方式/
動態排序
if @sord=“desc” then
CASE @sidx
WHEN ‘zj’ THEN
select * from ywtjb ORDER BY zj DESC;
WHEN ‘jj’ THEN
select * from ywtjb ORDER BY jj DESC;
WHEN ‘ys’ THEN
select * from ywtjb ORDER BY ys DESC;
WHEN ‘wbj’ THEN
select * from ywtjb ORDER BY wbj DESC;
WHEN ‘byxk’ THEN
select * from ywtjb ORDER BY byxk DESC;
WHEN ‘bj’ THEN
select * from ywtjb ORDER BY bj DESC;
WHEN ‘cswsl’ THEN
select * from ywtjb ORDER BY cswsl DESC;
WHEN ‘cswbj’ THEN
select * from ywtjb ORDER BY cswbj DESC;
WHEN ‘csybj’ THEN
select * from ywtjb ORDER BY csybj DESC;
WHEN ‘asbj’ THEN
select * from ywtjb ORDER BY asbj DESC;
WHEN ‘tqbj’ THEN
select * from ywtjb ORDER BY tqbj DESC;
END CASE;
else
CASE @sidx
WHEN ‘zj’ THEN
select * from ywtjb ORDER BY zj ASC;
WHEN ‘jj’ THEN
select * from ywtjb ORDER BY jj ASC;
WHEN ‘ys’ THEN
select * from ywtjb ORDER BY ys ASC;
WHEN ‘wbj’ THEN
select * from ywtjb ORDER BY wbj ASC;
WHEN ‘byxk’ THEN
select * from ywtjb ORDER BY byxk ASC;
WHEN ‘bj’ THEN
select * from ywtjb ORDER BY bj ASC;
WHEN ‘cswsl’ THEN
select * from ywtjb ORDER BY cswsl ASC;
WHEN ‘cswbj’ THEN
select * from ywtjb ORDER BY cswbj ASC;
WHEN ‘csybj’ THEN
select * from ywtjb ORDER BY csybj ASC;
WHEN ‘asbj’ THEN
select * from ywtjb ORDER BY asbj ASC;
WHEN ‘tqbj’ THEN
select * from ywtjb ORDER BY tqbj ASC;
END CASE;
end if;