数据库结构:
id, 利比亚内容
id Country
1 中国
2 阿根廷
3 中国
4 中国
5 法国
sql语句:SELECT Country FROM test GROUP BY Country
得到的结果是
Country
阿根廷
法国
中国 我想得到是按ID来排序的
即
中国
阿根廷
法国现在他自动按国家的名称顺序来排序,有什么办法可以按ID来排?
id, 利比亚内容
id Country
1 中国
2 阿根廷
3 中国
4 中国
5 法国
sql语句:SELECT Country FROM test GROUP BY Country
得到的结果是
Country
阿根廷
法国
中国 我想得到是按ID来排序的
即
中国
阿根廷
法国现在他自动按国家的名称顺序来排序,有什么办法可以按ID来排?
order by case Country when '中国' then 0 else 1 end
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);
Country
from
(
select
*
from
test t
where
id=(select min(id) from test where Country=t.Country))t
order by
t.id