项目中有一个这样需要按不同条件进行分类排序的需求,百度了半天,最后想了一种写法
(白色部分正序,灰色部分倒序)
这是用到union All SELECT * FROM (SELECT * FROM (SELECT openflag, opennumber, objid, productid, openstatu, end_date, start_date FROM plm_productopenperiod WHERE openflag = 1 ORDER BY start_date ASC) UNION ALL SELECT * FROM (SELECT openflag, opennumber, objid, productid, openstatu, end_date, start_date FROM plm_productopenperiod WHERE openflag = 0 ORDER BY start_date DESC))