能否这样排序

cloudgamer 2010-07-31 02:17:10
根据一个字段值是这样的
1 .a.b.c.d.e.
2 .a.b.c.
3 .a.
然后按匹配度排序
例如要匹配a b d
就按1 2 3排
要匹配b d
就按1 2排
有什么方法
...全文
88 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixianxxx 2010-07-31
  • 打赏
  • 举报
回复

if object_id('[tb]') is not null
drop table [tb]
create table [tb] (id int,col varchar(50))
insert into [tb]
select 1,'.a.b.c.d.e.' union all
select 2,'.a.b.c.' union all
select 3,'.a.'
GO
DECLARE @s VARCHAR(100)
SET @s='a b d'
SELECT k.id
FROM (
SELECT t.id,col=substring(stuff(t.col,1,1,''),s.number,charindex('.',stuff(t.col,1,1,''),s.number)-s.number)
FROM tb t JOIN master..spt_values s ON s.number BETWEEN 1 AND len(t.col)
WHERE s.type='p' AND substring(LEFT(t.col,len(t.col)-1),s.number,1)='.') k
WHERE charindex(k.col,@s)>0
GROUP BY k.id
HAVING(count(*)>0)
ORDER BY count(*) DESC
/*
id
----
1
2
3
*/
hokor 2010-07-31
  • 打赏
  • 举报
回复
if object_id('tb') is not null
drop table tb
select 1 id,'.a.b.c.d.e.' string into tb
union all select 2 id,'.a.b.c.'
union all select 3 id,'.a.'

declare @a table(col varchar(30))
insert into @a
select 'a b d' --查找字符串赋值
;with findstr as(
SELECT row_number()OVER(ORDER BY col)rn,col='.'+SUBSTRING(a.col,b.number,CHARINDEX(' ',a.col+' ',b.number)-b.number)+'.'
FROM @a a,master..spt_values b
WHERE b.number<=LEN(a.col)+1
AND CHARINDEX(' ',' '+a.col,b.number)=b.number
AND b.type = 'P')

select id,string,sum(isfind) sort from (
select t.id,t.string,case when charindex(f.col,t.string,0)>=1 then 1 else 0 end isfind from findstr f , tb t)
as a
group by id,string
order by sort desc

/* 'a b d'
id string sort
----------- ----------- -----------
1 .a.b.c.d.e. 3
2 .a.b.c. 2
3 .a. 1
*/

/* 'b d'
id string sort
----------- ----------- -----------
1 .a.b.c.d.e. 2
2 .a.b.c. 1
3 .a. 0
*/
pt1314917 2010-07-31
  • 打赏
  • 举报
回复

--这样?
--> 测试数据: [tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb] (id int,col varchar(50))
insert into [tb]
select 1,'.a.b.c.d.e.' union all
select 2,'.a.b.c.' union all
select 3,'.a.'
go

--匹配 a b d
select * from
[tb]
order by ((case when charindex('.a.',col)>0 then 1 else 0 end)+(case when charindex('.b.',col)>0 then 1 else 0 end)+(case when charindex('.d.',col)>0 then 1 else 0 end)) desc

duanzhi1984 2010-07-31
  • 打赏
  • 举报
回复
请详细点
duanzhi1984 2010-07-31
  • 打赏
  • 举报
回复
嘛????
xmx2009 2010-07-31
  • 打赏
  • 举报
回复
帮顶,接分
SQLCenter 2010-07-31
  • 打赏
  • 举报
回复
what?
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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