tabelA:id name postdate
1 aaa 2006-6-1
2 bbb 2006-6-33 aaa 2006-6-14 bbb 2006-6-3
用一条SQL语句查出1 aaa 2006-6-1
2 bbb 2006-6-3
也就是说将同时满足 name postdate 的重复记录去掉?谢谢!
1 aaa 2006-6-1
2 bbb 2006-6-33 aaa 2006-6-14 bbb 2006-6-3
用一条SQL语句查出1 aaa 2006-6-1
2 bbb 2006-6-3
也就是说将同时满足 name postdate 的重复记录去掉?谢谢!
解决方案 »
- sql server 2005 竞然有个这么弱智的BUG???
- ODBC连接数据库问题
- sql中同一个表的上下两行之间的某个字段相减问题
- 会员表设计
- 关于importfile()函数,大家帮个忙!!!!!!!!!!!!!!!!
- 如何外部合并多个表?
- 多条Insert语句插入超时问题。
- 求助:如何用代碼實現 Import Data的功能,或是使用命令行實現。
- ??? 继续请教SQL Server 7.0数据库设计的基本问题!
- SqlServer2014打开时提示找不到一个或多个组件,怎么解决???
- 简单的一个问题, 存储过程里面有Select语句,查询出来一个表的数据,我能不能把它当作一个表来用?
- 备份的数据库能保留id值吗
insert into @a select 1,'aaa','2006-6-1'
union all
select 2,'bbb','2006-6-3'
union all
select 3,'aaa','2006-6-1'
union all
select 4,'bbb','2006-6-3'
select name,postdate from @a group by name,postdate
select top 2 * from tableA order by id asc
create table tablea (
id int,
name varchar(10),
postdate varchar(10)
)insert into tablea
select 1,'aaa','2006-6-1' union all
select 2,'bbb','2006-6-3' union all
select 3,'aaa','2006-6-1' union all
select 4,'bbb','2006-6-3'
select * from tablea
/*id name postdate
----------- ---------- ----------
1 aaa 2006-6-1
2 bbb 2006-6-3
3 aaa 2006-6-1
4 bbb 2006-6-3(所影响的行数为 4 行)
*/select min(id) as id , name ,postdate
from tablea
group by name,postdate
/*
id name postdate
----------- ---------- ----------
1 aaa 2006-6-1
2 bbb 2006-6-3(所影响的行数为 2 行)
*/
select identity(int,1,1) AS id,name,postdate into #
from tablea
group by name,postdateselect *
from #
/*
id name postdate
----------- ---------- ----------
1 aaa 2006-6-1
2 bbb 2006-6-3(所影响的行数为 2 行)
*/