数据库结构:
id, 利比亚内容
id Country
1 中国      
2 阿根廷    
3 中国      
4 中国      
5 法国      
sql语句:SELECT Country FROM test GROUP BY Country
得到的结果是
Country
阿根廷    
法国      
中国      我想得到是按ID来排序的

中国
阿根廷 
法国现在他自动按国家的名称顺序来排序,有什么办法可以按ID来排?

解决方案 »

  1.   

    SELECT id,Country FROM test GROUP BY id,Country order by id
      

  2.   

    SELECT Country FROM test GROUP BY Country order by min(id)
      

  3.   

    怪了,你那个语句里要 group by 子句干嘛?你又不要统计什么.
      

  4.   

    SELECT Country FROM test GROUP BY Country
    order by  case Country when '中国' then 0 else 1 end 
      

  5.   

    我是要唯一的Country值呀。
      

  6.   

    飘走select distinct Country  from test  order by id
      

  7.   

    中国对应3个id,你用哪个,要是用最小的就用min()取出来排序
      

  8.   


    use tempdb;
    /*
    create table tb
    (
    id int not null,
    country nvarchar(10) not null
    );
    insert into tb(id,country)
    values
    (1,'中国'),
    (2,'阿根廷'),  
    (3,'中国'),
    (4,'中国'),
    (5,'法国');
    */
    select tb.country
    from tb
    group by tb.country
    order by MIN(tb.id);
      

  9.   

    select distinct Country from test order by id
      

  10.   

    select
     Country
    from
    (
    select
      *
    from 
      test t
    where
      id=(select min(id) from test where Country=t.Country))t
    order by 
      t.id
      

  11.   

    SELECT Country FROM test GROUP BY Country order by min(id)