2012-10-11 111 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

相关问题