- 浏览: 1196801 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (706)
- 全部博客(10000) (0)
- java基础 (123)
- 算法及数据结构 (64)
- SSH框架整合与平台系统分析 (11)
- j2ee (46)
- Oracle (95)
- SQL Server (11)
- javaScript (73)
- Ajax (22)
- jQuery (39)
- ExtJs (4)
- jsp (13)
- Servlet (6)
- struts1 (2)
- struts2 (33)
- Ibatis (2)
- hibernate (24)
- Spring (11)
- 设计模式 (8)
- 正则表达式 (9)
- UML (0)
- XML (9)
- linux (19)
- CSS (11)
- FreeMarker (4)
- nginx 与 memcached (6)
- SEO (5)
- Web 服务器 (11)
- junit 与 selenium2 (4)
- MyEclipse 有关的问题 (24)
- 生活杂感 (37)
- 看过的书 (2)
- 技术牛人 (2)
- 需要优化的例子 (3)
- English 学习 (7)
- bug修改的解决方法 (2)
- 数据库实战经验总结 (1)
- 期待解决的问题 (20)
- 等待自己学习的东西 (15)
- 自己公司代码结构总结 (15)
- 企业经营之道 (23)
- 工具管理 (1)
- 世范水晶 (2)
最新评论
-
hustkeai:
第一个方法是不对的
求一个Map中最大的value值,同时列出键,值 -
qq591920734:
java List 排序 Collections.sort() 对 List 排序(首先年龄排序,如果年龄相同,则按名字排序) -
qq591920734:
[color=orange][/color]包女包女不女
java List 排序 Collections.sort() 对 List 排序(首先年龄排序,如果年龄相同,则按名字排序) -
timer_yin:
seagrave 写道这个算法想法不错,但太耗时,我用1、2、 ...
用1、2、2、3、4、5这六个数字,数字排序经典算法 -
hellostory:
日常生活中,我们都不按你上面的那个方法算的!!!
JAVA小函数-计算日期差
一.简单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;
二.复杂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表的数据)
SQL>rename temp_emp to employee; (再将表重命名)
2)通过使用rowid来实现。
SQL>delete from employee where rowid not in (
select max(t1.rowid) from employee t1 group by
t1.emp_id,t1.emp_name,t1.salary);--这里用min(rowid)也可以。
四. TOP N问题:(用到rownum (oracle伪列))
--rownum只能使用<=或<的关系比较运算符
select * from s_emp where rownum <= 2;
--查询公司工资最高的3个人
/*select * from emp
where rownum <= 3
order by sal desc;*/ 错误的
select * from (select * from emp order by sal desc)
where rownum <= 3;
五.分页查询:
--查询第1-5条记录
select * from (select rownum num, s_emp.* from s_emp)
where num >=1 and num <= 5;
--按工资排序,五条一页,查找第二页
select salary,first_name
from(
select s.*, rownum rm
from (select *
from s_emp
order by salary d
) s
)
where rm between 6 and 10
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/SmartTony/archive/2008/01/24/2064238.aspx
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;
二.复杂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表的数据)
SQL>rename temp_emp to employee; (再将表重命名)
2)通过使用rowid来实现。
SQL>delete from employee where rowid not in (
select max(t1.rowid) from employee t1 group by
t1.emp_id,t1.emp_name,t1.salary);--这里用min(rowid)也可以。
四. TOP N问题:(用到rownum (oracle伪列))
--rownum只能使用<=或<的关系比较运算符
select * from s_emp where rownum <= 2;
--查询公司工资最高的3个人
/*select * from emp
where rownum <= 3
order by sal desc;*/ 错误的
select * from (select * from emp order by sal desc)
where rownum <= 3;
五.分页查询:
--查询第1-5条记录
select * from (select rownum num, s_emp.* from s_emp)
where num >=1 and num <= 5;
--按工资排序,五条一页,查找第二页
select salary,first_name
from(
select s.*, rownum rm
from (select *
from s_emp
order by salary d
) s
)
where rm between 6 and 10
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/SmartTony/archive/2008/01/24/2064238.aspx
发表评论
-
group by、order by与having、where,的位置先后。
2013-10-21 22:42 6126order by 是对数据进行排序,默认是升序ASC,降序 ... -
关于表分区的问题
2013-09-15 01:58 7881、分区表,按状态或时间,分开写再不同的表空间中,在查询的时 ... -
数据库 查询成绩及格的人
2013-09-11 22:53 9491、建表结构 -- 创建表create table ... -
大表加快查询方法
2013-09-07 16:44 934大表加快查询方法:表分区,建索引,根据where字段后的条 ... -
SQL语句优化:大批量循环插入数据的简化
2013-09-05 13:46 5765最近在学习SQL查询语句优化,试着弄个大数据量的数据库用来 ... -
oracle的nvl和nvl2是什么函数,两者区别是什么呢
2013-09-01 15:40 920NVL2(expr1,expr2,expr3) 功能:如 ... -
Oracle SQL性能优化
2013-08-29 22:29 833Oracle SQL性能优化 (1) 选择最有效 ... -
oracle over 用法
2013-06-27 11:56 538http://blog.csdn.net/xiuhaijua ... -
数据库中union 与union all 的区别
2013-06-07 14:49 900http://www.cn-java.com/www1/? ... -
SQL 左外连接,右外连接,全连接,内连接,自连接
2013-05-29 16:16 1184-- 左连接 ... -
Oracle 服务解释
2013-02-01 09:45 9231、OracleCSService 进程:ocssd.e ... -
添加 或修改字段
2012-10-16 11:39 9481、添加字段 Alter Table Rsc_In ... -
oracle 带参数的简单存储过程 的写法
2012-07-13 17:52 1276-- 下面代码都是在doc下面执行的。cmd -->&g ... -
SQLServer和Oracle,存储过程区别,常用函数对比
2012-03-23 16:44 10341、SQLServer和Oracle,存储过程区别,常用函数对 ... -
用sql语句 拷贝旧表中的数据(也就是创建一个完全一样的表,就是表名不同)
2012-03-16 11:24 1066-- 下面是oracle 的创建方式 CREATE TABL ... -
oracle 面试
2012-02-06 21:21 989面试题1、 prompt PL/SQL Developer ... -
oracle 11g win7 安装说明
2012-01-17 14:52 911安装的说明都在文档中:请下载文档! -
oracle中实现主键的自动增加
2012-01-16 14:30 881实现方法1: 建立一个最小为1,最大为nomaxval ... -
拼sql语句 批量删除
2011-12-06 14:22 1448String sql="delete from ... -
SQL中where 1=1语句的作用
2011-11-16 19:45 1370where 1=1有什么用?在SQL语言中,写这么一句话就跟没 ...
相关推荐
sql面试题,oracle面试题目,sql面试题\oracle面试题目
Oracle面试题目
Oracle面试题目及解答 轻松应对面试官
oracle经典面试题目及答案,面试必备。
oracle面试题目,想去吗?下载吧
oracle经典的50道面试题目。oracle经典的50道面试题目。oracle经典的50道面试题目。oracle经典的50道面试题目。祝大家好运!
个人收集的oracle面试题目.pdf
个人收集的oracle面试题目,有的没有吧.
oracle dba面试题目解答,非常实用,献给志向于数据库的同学.
里面收集一些面试oracle时的题目, 还有相应解答 里sql文件格式,导入到PL/SQL里就能运行,查看结果
1. 解释冷备份和热备份的不同点以及各自的优点 解答:热备份针对归档模式的数据库,在数据库仍旧处于工作状态时进行备份。而冷备份指在数据库关闭后,进行备份,适用于所有模式的数据库。热备份的优点在于当备份时...
经典的oracle面试题及答案,单表查询,多表关联查询,子查询,常用内置函数使用,多且全.
oracle 笔试面试题目
极详细oracle数据库面试题目汇总,按照这个思路去复习就可以了
oracle数据库面试题目汇总.pdf
oracle数据库面试题目集锦,非常不错
如何获得阿里技术offer:从《阿里DBA面试题》体味阿里社会招聘。16年的题,谨慎下载。内容为ORACLE数据库,有需要求可参考,刷题面试用
对在面试中最容易出现的问题等进行总结。 使你轻松顺利过关!
一份来自武汉英思工程科技有限公司的ORACLE面试测试题目,附答案