数据库笔试题(含参考答案) 1

来源:互联网 发布:手机版微信营销软件 编辑:程序博客网 时间:2024/06/12 18:29

数据库笔试题(含参考答案)

现在有个表:A(id ,name,regdate)
B(id,groupid) 

C(id,name2)
写出下面的SQL语句
1.统计A表中每个月注册用户数
2.统计A表中有姓名相同的用户数
3.如果表A中有姓名相同的用户,把相同的查出,写入表C中
4.A中ID有多个相同的数据,A中姓名相同的ID只保留注册时间最大的数据
大家帮帮忙,写一下吧



1
select count(*),to_char(regdate,'yyyymm') from A group by to_char(regdate,'yyyymm');
2
select count(*) from (select name from A group by name having count(*) >1);

insert into C(name2) select name from A group by name having count(*) >1;
4
delete from A E where e.regdate < (select max(regdate) from a X where E.id = X.id);

------
redate(格式为2007/02/12)

日期自己转化一下
SQL> select to_date('2007/02/12','yyyy/mm/dd') from dual;

TO_DATE('2007/02/12','YYYY/MM/
------------------------------
2007-2-12

 

 

 

 

学生表students_id    ints_name  varchar2课程表classc_id    intc_name  varchar2选课表xuankeid      ints_id    intc_id    int
查询出选了2门课以上的学生的信息
select * from student where s_id in ( select s_id from xuanke group by s_id having count(c_id) >2)

原创粉丝点击