T表:(字段:ID,NAME,ADDRESS,PHONE,LOGDATE)
E表:(字段:NAME,ADDRESS,PHONE)
1.将表T中的字段LOGDATE中为2001-02-11的数据更新为2003-01-01,请写出相应的SQL语句。(该字段类型为日期类型)
update t
setlogdate=to_date('2003-01-01','yyyy-mm-dd')
wherelogdate=to_date('2001-02-11','yyyy-mm-dd');
2.请写出将表T中NAME存在重复的记录都列出来的SQL语句(按NAME排序)
select *
from t
where name in (select name from t group by name having coung(*)>1)
orderby name;--没说清楚,到底是升序还是降序
select * from T where rowid not in(select max(rowid) from T group by ID,NAME,ADDRESS,PHONE,LOGDATE);
3.请写出题目2中,只保留重复记录的第一条,删除其余记录的SQL语句(即使该表不存在重复记录)
delete from T where rowid not in(select max(rowid) from T group by ID,NAME,ADDRESS,PHONE,LOGDATE);
select ID,NAME,ADDRESS,PHONE,LOGDATE
from
(selectt.*,row_number() over(partition by name order by name) rn
from t)
where rn =1;
4.请写出将E表中的ADDRESS、PHONE更新到T表中的SQL语句(按NAME相同进行关联)
update t
set(address,phone)=
(selectaddress,phone from e where e.name=t.name);
update T
setT.ADDRESS=(select E.ADDRESS from E where E.NAME=T.NAME),
T.PHONE=(selectE.PHONE from E where E.NAME=T.NAME);
5.请写出将T表中第3~5行数据列出来的SQL语句
SELECT *
FROM t
WHERE rownum <= 5
MINUS
SELECT *
FROM t
WHERE rownum <= 2;
select *from (select rownum as xx,T.* from T) where xx between 3 and 5;
请问csuxp-2008总裁大人,这里,那个题目是oracle的特别之处,我意思是和普通sql语句不同的地方。谢谢请指名,我愚笨
也没什么特别的地方,有些题目用oracle特有的函数去做会比较简单,像在第三题中用到的oracle的分析函数,以及在第一题中用到的oracle的to_char()函数。
这几个题目主要是看你能不能使用oracle的函数去处理