0

我的表格中有两种类型的交易1)One way relocation deal and 2)Regular deal。我的 db -Vehicles 中有一张桌子。

vehicles table
=====================================================
id, pickuplocation, returnlocation, included location

现在,当用户One way relocation deal在 db 中选择 then 时,只会id,pickuplocation,returnlocation插入并且该列included location将为空。当用户选择时Regular deal,该列将为pickuplocation,returnlocation空,只有列id and included location将设置。问题是我想使用他们的位置对整个数据进行排序。我试过这个查询 -

SELECT * 
FROM vehicles 
where 1=1 
ORDER BY pickuplocation ASC,returnlocation ASC

但它不会给出正确的结果,因为某些数据在包含的位置为空。我如何对所有数据进行排序pickuplocation,returnlocation,exculded location

4

3 回答 3

0

你想要的IFNULL功能

尝试排序

 IFNULL(returnlocation, includedlocation)
于 2012-06-28T09:47:27.847 回答
0

得到了解决方案。我使用了这个查询

(SELECT id,pickuplocation,returnlocation,deal_type FROM `vehicles` where deal_type = 1)

UNION

(SELECT id,included_location,excluded_location,deal_type FROM `vehicles`  where deal_type = 2)

order by pickuplocation,returnlocation

我希望这对将来可能遇到类似问题的人有所帮助。

于 2012-06-28T09:47:37.240 回答
0
SELECT * 
FROM vehicles 
where 1=1 AND ($condition) 
ORDER BY pickuplocation ASC,returnlocation ASC

假设$condition将类似于field01=1ORfield2 >=1

于 2012-06-28T10:01:02.253 回答