Need help for complex data sort SQL Server

后端 未结 2 1241
广开言路
广开言路 2021-01-24 03:06

I need help for complex data sort from database. Suppose my data stored in table like this:

Description
--------------
JCB Excavator - ECU P/N: 728/35700
Geo Pri         


        
2条回答
  •  有刺的猬
    2021-01-24 03:33

    Here you go

    declare @t table(Description varchar(1000))
    insert into @t
    select 'JCB Excavator - ECU P/N: 728/35700 ' union all
    select 'Geo Prism 1995 GEO - ABS #16213899 GEO pump ' union all
    select 'Geo Prism 1995 - GEO ABS #16213897 ' union all
    select 'Geo Prism 1995 - ABS #16213897 ' union all
    select 'Ersatz Airbags, Gurtstrammer und Auto Körper  Teile ' union all
    select 'this test JCB pipe & JCB pump ' union all
    select 'Wie man BBA reman erreicht'
    
    declare @search_term varchar(100)
    set @search_term ='GEO'
    select Description from @t
    order by len(Description)-len(replace(Description,@search_term,'')) desc
    

    Result

    Description
    ----------------------------------------------------------
    Geo Prism 1995 GEO - ABS #16213899 GEO pump 
    Geo Prism 1995 - GEO ABS #16213897 
    Geo Prism 1995 - ABS #16213897 
    Ersatz Airbags, Gurtstrammer und Auto Körper  Teile 
    this test JCB pipe & JCB pump 
    Wie man BBA reman erreicht
    JCB Excavator - ECU P/N: 728/35700 
    

提交回复
热议问题