Database query to search using address

前端 未结 2 1326
滥情空心
滥情空心 2021-01-26 06:01

I am developing a search functionality to search for dealers by their address(i.e. by postcode(zip) or by name or by city)for my project. user will be provided with only one htm

2条回答
  •  有刺的猬
    2021-01-26 06:24

    Life would be easier if all your terms were sorted in ascending order.

    I assume that your actual application is using a variable rather than a hard-coded string. So the solution should look something like this:

      select city, postcode, name
      from dealers
      where name = p_search_term OR
            postcode = p_search_term OR
            city = p_search_term
      ORDER BY case when postcode = p_search_term then p_search_term else 1 end desc
               , case when name = p_search_term then p_search_term else city end asc
    

提交回复
热议问题