dory4404
2015-07-16 05:42
浏览 55
已采纳

pdo按相关性排序,然后按另一个字段排序

I have a query that selects from my database and then orders by relevance:

select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc LIMIT :start, :limit

When these results are shown I want the user to have an option of filtering by price. How can I do this when ORDER BY is already used for the relevance?

Can I create a view of the results and then query the view to filter by price?

图片转代码服务由CSDN问答提供 功能建议

我有一个查询从我的数据库中选择,然后按相关性排序: < pre> select * from`table`其中MATCH(`name`)AGAINST(:搜索IN BOOLEAN MODE)命令由MATCH(`name`)AGAINST(:search2 IN BOOLEAN MODE)desc LIMIT:start,:limit \ n

当显示这些结果时,我希望用户可以选择按价格过滤。 当ORDER BY已用于相关性时,我该怎么做?

我可以创建结果视图,然后查询视图以按价格过滤吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanboxue3422 2015-07-16 06:05
    已采纳

    you can Order by as many columns as you want. Syntax is:

    ORDER by column1 desc, column2 asc, column3 desc ...
    

    So you might want to have:

    select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc, `price` asc LIMIT :start, :limit
    

    If you want a price Range you have to build it into an WHERE clause

    select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) AND `price` >= 5 AND `price` < 10 order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc, `price` asc LIMIT :start, :limit
    
    点赞 打赏 评论

相关推荐 更多相似问题