Order by Maximum condition match

前端 未结 4 554
名媛妹妹
名媛妹妹 2020-12-16 22:09

Please help me to create a select query which contains 10 \'where\' clause and the order should be like that: the results should be displayed in order of most keywords(where

4条回答
  •  醉梦人生
    2020-12-16 23:02

    There are many options/answers possible. Best answer depends on size of the data, non-functional requirements, etc.

    That said, what I would do is something like this (easy to read / debug):

      Select * from 
        (Select *, iif(condition1 = bla, 1, 0) as match1, ..... , match1+match2...+match10 as totalmatchscore from sourcetable
        where 
          condition1 = bla or
          condition2 = bla2
          ....) as helperquery
        order by helperquery.totalmatchscore desc
    

提交回复
热议问题