if object_id('td_species') is not null
drop table td_species;
create table td_species([id] int,sp_name varchar(20));
insert into td_species
select 1, 'rice' union
select 2, 'maize'union
select 3, 'wheat' union
select 4, 'wheat';
select * from td_species;id sp_name
-----------------------------
1 rice
2 maize
3 wheat
4 wheat
我现在想用一条select语句想输出这样的结果,我应该怎么写?id sp_name
-----------------------------
1 rice
2 maize
3 wheat
即:我想把sp_name列重复的去除,并且输出id的编号.
drop table td_species;
create table td_species([id] int,sp_name varchar(20));
insert into td_species
select 1, 'rice' union
select 2, 'maize'union
select 3, 'wheat' union
select 4, 'wheat';
select * from td_species;id sp_name
-----------------------------
1 rice
2 maize
3 wheat
4 wheat
我现在想用一条select语句想输出这样的结果,我应该怎么写?id sp_name
-----------------------------
1 rice
2 maize
3 wheat
即:我想把sp_name列重复的去除,并且输出id的编号.
Where (Select Count(1) From td_species Where sp_name= A.sp_name And id> A.id) < 1
我说这个呵呵