小区名称      categroy春天花园       1
未知小区       2
东方花园       1
房改房小区     3 sql 2000 怎么实现排序?
(要求 未知小区放第一位 然后再按小区名称排序)
大家帮帮忙!

解决方案 »

  1.   

    select * from tb order by case 小区名称 when '未知小区' then 0 else 1 end,小区名称
      

  2.   

    --========+++++++++++++++++++++++++++++++++++==========
    --======= 每天都在进步,却依然追不上地球的自传=========
    --======= By: zc_0101 At:2010-04-08 11:22:01=========
    --========++++++++++++++++++++++++++++++++++++=========
    --> 测试数据: #a
    if object_id('tempdb.dbo.#a') is not null drop table #a
    create table #a (小区名称 varchar(10),categroy int)
    insert into #a
    select '春天花园',1 union all
    select '未知小区',2 union all
    select '东方花园',1 union all
    select '房改房小区',3
     
    ----------------查询------------
    select * from #a order by case 小区名称 when '未知小区' then 0 else 1 end,小区名称
    ----------------结果--------------
    /*
    小区名称 categroy
    未知小区 2
    春天花园 1
    东方花园 1
    房改房小区 3
    */
      

  3.   


    select * from tab order by case when  小区名称 = '未知小区' then 0 else 1 end , 小区名称
      

  4.   

    select * from tb order by case 小区名称 when   '未知小区' then 0 else 1 end , 小区名称
      

  5.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2010-04-08 11:24:36
    -- Verstion:
    --      Microsoft SQL Server 2005 - 9.00.4053.00 (Intel X86) 
    -- May 26 2009 14:24:20 
    -- Copyright (c) 1988-2005 Microsoft Corporation
    -- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([小区名称] varchar(10),[categroy] int)
    insert [tb]
    select '春天花园',1 union all
    select '未知小区',2 union all
    select '东方花园',1 union all
    select '房改房小区',3
    --------------开始查询--------------------------
    select * from tb order by  charindex(小区名称,'未知小区') desc,小区名称
    ----------------结果----------------------------
    /* 小区名称       categroy
    ---------- -----------
    未知小区       2
    春天花园       1
    东方花园       1
    房改房小区      3(4 行受影响)
    */
      

  6.   

    if object_id('tempdb.dbo.#a') is not null drop table #a
    create table #a (小区名称 varchar(10),categroy int)
    insert into #a
    select '春天花园',1 union all
    select '未知小区',2 union all
    select '东方花园',1 union all
    select '房改房小区',3
    select * from #a order by (case when 小区名称='春天花园' then 1 else 2 end) desc小区名称       categroy
    ---------- -----------
    未知小区       2
    东方花园       1
    房改房小区      3
    春天花园       1(4 行受影响)
      

  7.   

    if object_id('tempdb.dbo.#a') is not null drop table #a
    create table #a (小区名称 varchar(10),categroy int)
    insert into #a
    select '春天花园',1 union all
    select '未知小区',2 union all
    select '东方花园',1 union all
    select '房改房小区',3select * from #a order by (case when 小区名称='未知小区' then 1 else categroy+1 end) asc小区名称       categroy
    ---------- -----------
    未知小区       2
    东方花园       1
    春天花园       1
    房改房小区      3(4 行受影响)
      

  8.   

    select * from categroy order by case [name] when '未知小区' then 0 else 1 end,[name]
      

  9.   


    小区名称 categroy春天花园 1
    未知小区 2
    东方花园 1
    房改房小区 3  sql 2000 怎么实现排序?
    (要求 未知小区放第一位 然后再按小区名称排序)
    大家帮帮忙!select * from #a order by case when 小区名称='未知小区' then 0 else 1 end,小区名称