SQL ORDER BY具有多个参数的情况

时间:2018-01-15 10:27:14

标签: php mysql sql mysqli

我想订购这样的结果:

$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

有可能吗?

1 个答案:

答案 0 :(得分:1)

如果您希望项目按其他标准按ID排序,您只需将其添加到ORDER BY子句的末尾即可...

$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";