查询name,要求
matches on first, middle or last name, ordered by last name matches first
就是对输入条件进行first, middle or last name上的匹配,结果集要按照last name有匹配的排在前面排列。

解决方案 »

  1.   

    就是对输入条件进行first, middle or last name上的匹配,结果集要按照last name有匹配的排在前面排列
    看不明白
      

  2.   

    firstname | middle name |last name
    a b c
    b c a
    c a b
    三条记录查询条件 a 输出
    b c a
    a b c
    c a b不用union行不行?
      

  3.   

    --> 测试数据: #T
    if object_id('tempdb.dbo.#T') is not null drop table #T
    create table #T (firstname varchar(11),middlename varchar(11),lastname varchar(11))
    insert into #T
    select 'a','b','c' union all
    select 'b','c','a' union all
    select 'c','a','b'select * from #T where firstname='a' or middlename='a' or lastname='a' order by charindex('a',lastname) desc, lastname/*
    firstname   middlename  lastname
    ----------- ----------- -----------
    b           c           a
    c           a           b
    a           b           c
    */
      

  4.   

    select * from tb
    where firstname = @name
    or middlename = @name
    or lastname = @name 
    order by lastname
      

  5.   


    select * from tb ... last name
    union all
    select * from tb ... first 
    ....
      

  6.   

    select * from tb where case when lastname = @name then 0 else 1 end
      

  7.   

    select * from tb order by  case when lastname = @name then 0 else 1 end