我有类似的表格如下:
Name city state country
---- ---- ----- -------
Sree mm ap ind
SRee redmond ny us
rahul hyd ap ind
xxx mm ap ind
abcd mm tn ind
wer dd ap ind
如果我使用mm,ap
进行搜索,我需要获取这些内容。
Name city state country
---- ---- ----- -------
Sree mm ap ind
xxx mm ap ind
abcd mm tn ind
wer dd ap ind
如果这两个单词匹配,那么如果在city
秒作为州,第三个作为国家/地区包含,则它应该首先出现。
请帮助我。
答案 0 :(得分:2)
declare @city nvarchar(50) = 'mm',
@state nvarchar(50) = 'ap'
Select *
From (Select *
from YourTable
Where city = @city or state = @state
)z
order by Case When city = @city and state = @state Then 1
When City = @city then 2
Else 3
end