1、忍不住想说一句,因为第一题中的字段类型是 【日期型】,而各种数据库操作日期型数据有不同的方法,没有一种共通的方法,所以脱离了数据库而言没有一种共通的sql。
2、select ID,NAME,ADDRESS,PHONE,LOGDATE from T
where ID in( select ID from T group by NAME having count(*)>1)
order by NAME;
3、delete from T where ID not in
(select min(id) from T group by name);
4、update T
set T.ADDRESS=(select E.ADDRESS from E where E.NAME=T.NAME),
T.PHONE=(select E.PHONE from E where E.NAME=T.NAME);
5、这个不同的数据库也有不同的处理方法,不能脱离数据库谈了。
如:SqlServer或者access可以使用 top
oracle可以使用 rownum 等
---
以上,希望对你有所帮助。
1:update T表 set LOGDATE = 2003-01-01 where LOGDATE = 2001-02-11
2:select * from T表 where name = name order by name
3:select distinct name from T表 where name = name
4、update T set T.ADDRESS=(select E.ADDRESS from E where E.NAME=T.NAME),T.PHONE=(select E.PHONE from E where E.NAME=T.NAME);
5、这个不同的数据库也有不同的处理方法,不能脱离数据库谈了。
如:SqlServer或者access可以使用 top
oracle可以使用 rownum 等
可以给你地址自己学习一下:
http://blog.163.com/shidio/blog/static/17630584200982233532890/
1、update T set LOGDATE = '2003-01-01' where LOGDATE = '2001-02-11'
2、select * from T where rowid not in(select max(rowid) from T group by ID,NAME,ADDRESS,PHONE,LOGDATE);
3、delete from T where rowid not in(select max(rowid) from T group by ID,NAME,ADDRESS,PHONE,LOGDATE);
4、update T
set T.ADDRESS=(select E.ADDRESS from E where E.NAME=T.NAME),
T.PHONE=(select E.PHONE from E where E.NAME=T.NAME);
5、select * from (select rownum as xx,T.* from T) where xx between 3 and 5;
以上都是亲自试过以后才回答的
1. update T set logdate = '2003-1-1' from T where logdate='2001-2-11'
2.select * from e a where not exists (select count(1) from e where name = a.name) = 1
3.delect from e a where not exists(select distinct 1 from e where name = a.name)
4.update t set address = a.address,phone=a.phone from t inner join e a on a.name = t.name
5. alter table add id int identity(1,1) go
select * from T where id between 3 and 5
以上是SQL Server 代码.第三句可能有点问题.我这边没有测试环境和数据不好意思
1.
select
s.title,
count(p.id)
from
书表
s
left
join
评论
p
on
s.id=p.书表中的id
group
by
s.title
(注意:左外连接的作用是将评价数为0的书显示出来.count(p.id)和count(*)的区别是count(p.id)不计入p.id为null的行)
2.
select
top
1
s.title,
count(p.id)
from
书表
s
left
join
评论
p
on
s.id=p.书表中的id
group
by
s.title
order
by
2
desc
(以第2列倒序排序,取第1行)