关于排序的。

jamfchan 2007-06-29 07:45:51
有什么办法可以搜索 某一表中的一列, 按匹配的程度排序呢?
例如,查标题是“美女”的,将标题是“美女”的放在前面,接着就放"%美女%"的,也按匹配的程度排列?

例如标题表中有
table1
title
她是美女
美女
臭美的女人
美女快来啊

以上如果搜 “美女”
就按
美女
她是美女
美女快来啊
排序列出来。
帮帮忙,谢谢。。。
...全文
186 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2007-07-01
  • 打赏
  • 举报
回复
偶看错答案也有分~~~~~~~~~~,哈哈

select * from table1 where charindex('美女',title) >0
order by len(title) asc,charindex('美女',title) asc--加多一个排序规则
jamfchan 2007-06-29
  • 打赏
  • 举报
回复
对哦,谢谢各位
中国风 2007-06-29
  • 打赏
  • 举报
回复
select * from table1 where charindex('美女',title) >0 order by charindex('美女',title) asc
bqb 2007-06-29
  • 打赏
  • 举报
回复

create table table1(title varchar(20))
insert into table1
select '她是美女'
union all
select '美女'
union all
select '臭美的女人'
union all
select '美女快来啊'

select * from table1 where title like '%美女%' order by len(title)

/*
titlt
-----------
美女
她是美女
美女快来啊

*/

drop table table1
bqb 2007-06-29
  • 打赏
  • 举报
回复
select * from table1 where title like '%美女%' order by len(title)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧