在USERS表中,有如下数据:
number (int) name (varchar)
1 a
2 b
3 b
4 c
5 a
6 b
7 c
利用SQL的delete语句取到如下结果:
number(int) name(varchar)
1 a
2 b
4 c
也就是说:如果name 有相同的值时,取number 最小的那个.
利用SQL的delete语句(只有一条SQL语句)。
谢谢。
number (int) name (varchar)
1 a
2 b
3 b
4 c
5 a
6 b
7 c
利用SQL的delete语句取到如下结果:
number(int) name(varchar)
1 a
2 b
4 c
也就是说:如果name 有相同的值时,取number 最小的那个.
利用SQL的delete语句(只有一条SQL语句)。
谢谢。
解决方案 »
- 急急急急!SQL2000数据库表的内容被误删.请问怎么能恢复!记录格式是新建格式..不是覆盖。。 急急急 有尝求人解决!QQ:727979739 送一年QQ会员
- 问高手一个小问题!
- 动态SQL如何拼写两个时间的比较
- 计数问题
- 100分急求一个简单的sql,要求执行效率高就可以,谢谢
- 满分求一SQL语句或存储过程或算法
- set 语句错误 ,对数据类型而言运算符无效,如何解决
- 100分求教:.db数据库的连接问题
- 如何自动接转帐目(马上结账!谢谢!)
- 在 NT4.0 上执行 SQL server 安装光盘上的文件 autorun.exe 出错?
- 请教个小问题,谢谢!!!!!!!!!!!!!!!!!!!!!!
- sql2005中添加一個用戶
if object_id('tempdb.dbo.#') is not null drop table #
create table #(number int, name varchar(8))
insert into #
select 1, 'a' union all
select 2, 'b' union all
select 3, 'b' union all
select 4, 'c' union all
select 5, 'a' union all
select 6, 'b' union all
select 7, 'c'select min(number) number, name from # group by name
/*
number name
----------- --------
1 a
2 b
4 c
*/
go
create table [users]([number] int,[name] varchar(1))
insert [users]
select 1,'a' union all
select 2,'b' union all
select 3,'b' union all
select 4,'c' union all
select 5,'a' union all
select 6,'b' union all
select 7,'c'
delete users
where exists(select 1 from users t where t.name=users.name and t.number<users.number)select * from users
/**
number name
----------- ----
1 a
2 b
4 c(3 行受影响)
**/