我在mySQL中写了一个过程,
IN `para` varchar(4)
BEGIN
#Routine body goes here...
if (para = 'asc') THEN
SELECT officeCode, city, country
from offices
ORDER BY country ;
ELSE
SELECT officeCode, city, country
from offices
ORDER BY country DESC;
END if;
END
这段代码没问题,但我想知道有没有其他方法可以缩短,像这样(para是调用过程时的参数):
BEGIN
SELECT officeCode, city, country
from offices
ORDER BY country *para* ;
END
--------but this is not work-------
最佳答案
您可以使用您选择的任何脚本语言根据 para
非常轻松地动态生成查询的文本,如果这在您的解决方案中可行的话。
关于mysql - 如何按 DESC 按语句顺序放置字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40645549/