所以有一个主要的 WHERE 子句条件,我想要我的结果,但是我有另一个条件,我希望满足这两个条件的结果首先出现在结果数组中,然后是只满足主要条件的结果。一种可能的方法可能是首先根据主要结果进行选择,然后使用第二个条件进行操作。但我想看看是否有办法通过 mysql select 语句本身来做到这一点。
3 回答
            1        
        
		
重新阅读您的问题后,我了解您不想按第二个标准过滤结果,而是简单地重新排序。在这种情况下,请使用 custom ORDER BY,例如:
SELECT *
FROM mytable
WHERE x = 'major'
ORDER BY (y = 'minor') DESC
    于 2012-12-29T08:29:28.370   回答
    
    
            0        
        
		
在关闭的地方使用 with block to multipal
块引用
与 t 作为 {
select * from table a where a.columnname = 1
}, p 为 {
select * from table b where b.columnname = 2
}
于 2012-12-29T08:29:57.157   回答
    
    
            0        
        
		
您可以根据您的条件订购。
select some_columns 
  from a_table 
 where major_condition
 order by if(minor_condition, 1, 0)
    于 2012-12-29T08:30:41.147   回答