易截截图软件、单文件、免安装、纯绿色、仅160KB

oracle sql面试题2

一.简单SQL查询:
1):统计每个部门员工的数目
select dept,count(*) from employee group by dept;
2):统计每个部门员工的数目大于一个的记录
select dept,count(*) from employee group by dept having count(*)>1;
3):统计工资超过1200的员工所在部门的名称
select e.first_name,salary,d.name
from s_emp e, s_dept d
where e.dept_id = d.id
and salary > 1200;
4):查询哪个部门没有员工
select e.empno, d.deptno
from emp e, dept d
where e.deptno(+) = d.deptno
and e.deptno is null;
or
select *
from dept d
where not exists(select 1 from emp e
                            where e.deptno = d.deptno
                           );
二.复杂SQL查询
有3个表(15分钟):(SQL)
Student 学生表 (学号,姓名,性别,年龄,组织部门)
Course 课程表 (编号,课程名称)
Sc 选课表 (学号,课程编号,成绩)
表结构如下:
 
1)    写一个SQL语句,查询选修了’JAVA’的学生学号和姓名(3分钟)
答:SQL语句如下:
select stu.sno, stu.sname
from student stu, course c, sc
where stu.sno = sc.sno
and sc.cno = c.cno
and c.cname=’JAVA’;
2)    写一个SQL语句,查询’a’同学选修了的课程名字(3分钟)
答:SQL语句如下:
select stu.sname, c.cname
from student stu, course c, sc
where stu.sno = sc.sno
and sc.cno = c.cno
and stu.sname = ’a’;
3)    写一个SQL语句,查询选修了5门课程的学生学号和姓名(9分钟)
答:SQL语句如下:
select stu.sno, stu.sname
from student stu
where (select count(*) from sc where sno=stu.sno) = 5;
三. 在SQL中删除重复记录的方法:(用到rowid (oracle伪列))
1)通过建立临时表来实现
SQL>create table temp_emp as (select distinct * from employee) 
SQL>truncate table employee; (清空employee表的数据)


相关文档:

redhat linux 5下oracle10.2安装总结

在linux下安装oracle是件繁琐的事情。具体来讲分为一下几大步:
1.修改系统版本
vi /etc/redhat-release
注释掉第一行,添加一行:redhat-4
2.安装软件包
rpm -Uvh setarch-2*
rpm -Uvh make-3*
rpm -Uvh glibc-2*
rpm -Uvh libaio-0*
rpm -Uvh compat-libstdc++-33-3*
rpm -Uvh compat-gcc-34-3*
rpm -Uvh comp ......

linux下创建oracle用户表空间

 就是在已有的数据库实例上创建一个新的帐号,访问一些新的表
 操作步骤如下:
 1、登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户)
 2、以sysdba方式来打开sqlplus,命令如下: sqlplus "/as sysdba"
 3、查看我们常规将用户表空间放置位置 ......

SQL SERVER 2000 安装提示"一般性网络错误"

 今天安装SQL SERVER 2000 个人版,安装最后弹出错误对话框:
“安装程序配置服务器失败。参考服务器错误日志和C:\windows\sqlstp.log”,从而无法安装。
到具体的目录查看显示"一般性网络错误",在网上搜索问题原因及解决方案如下:
此问题属于sql server的bug, GetComputerName 用于获取本地计算机名。 ......

在sql*plus下设置autotrace

    我们在工作中希望能看见自己运行的DML语句的运行报告,例如select,delete,update,megre和insert语句运行后的情况,以用来监视和调优语句。我们通常在sql*plus中使用set autotrace on开启。
    那autotrace是如何安装的呢?thomas kyte的大作中给出了详细的方法和解释:
  & ......

一个字段匹配的sql语句书写

这几天负责一个家教门户网站的开发,基于cakephp框架。在培训机构表(schools)中存在一个字段subject用来存储另一个数据表
(subjects)中记录的id值,且存储形式为:'1,2,3,4,5'。但是在应用高级搜索过滤时页面select选项option的传值为
subjects的id值,需要判断查询表schools中subject字段存在此id,即查询显示此记录 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号