2012-10-11 110 views
1

我會盡力解釋我的問題。按照自定義標準對搜索結果進行排序

我有一個搜索表單,用戶可以選擇不同的參數並輸入不同的值來執行屬性搜索。就像我有一張桌子tbl_properties

在搜索表單用戶選擇property_categoryproperty_type [租賃,出售或出租],輸入價格範圍,no_of_bedroomslocationdistrictsproperty_area等屬性的屬性可以是在tbl_properties或其它查找表。編寫查詢是不是我的問題,但我米的問題是,我想在搜索以下模式記錄排序

  1. 首秀的結果 - 價格是按降序排列
  2. 然後顯示相匹配的位置 - 價格匹配區
  3. 然後顯示 - 在同一個分區沒有臥室的比賽
  4. 再展 - 價格/房/物業面積相匹配,但在不同地區

我只想一個提示如何CA記錄按這些順序排序?

編輯

這裏是表結構的簡要說明我

感謝

+0

你確定你的意思的價格降序一個很好的鏈接?如最高價格在先? –

+0

請提供您的架構。 – RedFilter

+0

@RedFilter,請參閱我的編輯 – Sharmila

回答

3
order by case 
    when price between @priceMin and @priceMax 
     and location = @location then 1 
    when price between @priceMin and @priceMax 
     and district_id = @districtid then 2 
    when no_of_bedrooms = @no_of_bedrooms 
     and districtid = @districtid then 3 
    when price between @priceMin and @priceMax 
     and no_of_bedrooms = @no_of_bedrooms 
     and property_area = @property_area and districtid <> @districtid then 4 
    else 5 
end, price desc 
+0

非常感謝很多朋友的工作 – Sharmila

-1

選擇tbl_properties property_category房產類型,其中_ __ _ __ _ORDER BY_ __;

so ... ORDER BY price desc;

下面是使用http://www.sqlcourse2.com/orderby.html

+0

這不是我想要的,請仔細閱讀我的問題。 – Sharmila

相關問題