我的表中有四列sale date 4
, sale date 3
, sale date 2
,sale date
都是销售日期。在页面sale date 4
中显示时,如果它不为空,我们将优先显示它,如果它是空的,则来sale date 3
,然后sale date 2
,然后sale date
。
我的问题是在对结果进行排序时。
何时使用 order by 运行查询
order by
isnull(`sale date 4`), trim(`sale date 4`) ,
isnull(`sale date 3`), trim(`sale date 3`) ,
isnull(`sale date 2`), trim(`sale date 2`) ,
isnull(`sale date`), trim(`sale date`) asc
我得到的结果如下
**sale date 4** | **sale date 3** | **sale date 2** | **sale date**
--------------------------------------------------------------------
2013-01-24 | 2013-01-24 | 2013-01-24 | 2013-01-24
2013-01-31 | 2013-01-31 | 2013-01-31 | 2012-11-30
2013-02-01 | 2013-02-01 | 2013-02-01 | 2013-02-01
2013-03-08 | 2013-03-08 | 2013-03-08 | 2013-03-08
----NULL---- | ----NULL---- | 2013-02-28 | 2012-11-02
----NULL---- | ----NULL---- | ----NULL---- | 2013-02-28
当我在视图中显示时,它将如下
1. Sale date = 2013-01-24
2. Sale date = 2013-01-31
3. Sale date = 2013-02-01
4. Sale date = 2013-03-08
5. Sale date = 2013-02-28
6. Sale date = 2013-02-28
但我需要的是
1. Sale date = 2013-01-24
2. Sale date = 2013-01-31
3. Sale date = 2013-02-01
4. Sale date = 2013-02-28
5. Sale date = 2013-02-28
6. Sale date = 2013-03-08
我怎样才能做到这一点?