sql多参数逐案排序

i5desfxk  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(242)

我想把我的结果排序如下:

$query_resultat .= "ORDER BY case
when vendue = 'AV' then 1
when vendue = 'VPNA' then 2
when vendue = 'EC' then 3
when vendue = 'V' then 4
when vendue = 'SCDV' then 5
else 6 end";

但我想问是否有可能再加上这样的条件:
先订购结果 when vendue = 'AV' 并对结果进行排序 by Id DESC 在第二次,秩序的结果 when vendue = 'VPNA' 并对结果进行排序 by ID DESC 有可能吗?

dwbf0jvd

dwbf0jvd1#

如果您想在其他条件中按id排序,您可以将其添加到ORDERBY子句的末尾。。。

$query_resultat .= "ORDER BY case
      when vendue = 'AV' then 1
      when vendue = 'VPNA' then 2
      when vendue = 'EC' then 3
      when vendue = 'V' then 4
      when vendue = 'SCDV' then 5
      else 6 
    end,
    ID DESC";

相关问题