我想在SQL Server中搜索。当我进入" A bang",并使用"喜欢'%A爆炸%'",并按...排序...
我想安排以" A bang"之后,结果包含" A bang"但不要开始说话。
SELECT *
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY CLNTPFX ASC, CLNTCOY ASC,
SURNAME ASC, GIVNAME ASC,
CLNTNUM ASC, UNIQUE_NUMBER DESC) ROWN,
TEMP1.*
FROM
(SELECT *
FROM CLNTPF
WHERE CLNTPFX = 'CN'
AND CLNTCOY = '9'
AND SURNAME LIKE 'A Bang'
AND VALIDFLAG = 1) TEMP1) TEMP2
WHERE
ROWN > 12
AND ROWN <= 24
搜索&#34; O&#34;
时的预期示例Owner
Owner
Owner
Owner
Owner
A Owner
A Owner
A Owner
你可以帮帮我吗?
全部谢谢!
答案 0 :(得分:1)
假设c1
是您要对数据进行排序的列,其方式是首先显示以O
开头的字词,然后是文字中某处有O
的字词。 ,然后是所有其他单词,您可以在查询中添加order by
,如下所示。
ORDER BY CASE
WHEN c1 LIKE 'O%'
THEN 1
WHEN c1 LIKE '%O%'
THEN 2
ELSE 3 end;
在您的样本数据上,结果如下。
C1
------------------------
Owner
Owner
Owner
Owner
A Owner
A Owner
A Owner
您可以查看演示 here