标签:and select tran 单个字符 情况 llb like 表数据 分组
Select
Where
Group by, Having
Order by
Delete
Update
Insert
Create
Alter
Drop
TRUNCATE
GRANT
REVOKE
BEGIN TRANSACTION
COMMIT
ROLLBACK
DECLARE CURSOR
FETCH INTO
select empno,ename,job,mgr,hiredate,sal,comm,deptno
from emp
where empno=7369 or empno = 7521 or empno = 7566;
or
select empno,ename,job,mgr,hiredate,sal,nvl(comm,1),deptno
from emp
where empno in (7369,7521,7566);
select empno,ename,job,mgr,hiredate,sal,comm,deptno
from emp
where empno=7369 or empno = 7521 or empno = 7566;
select empno,ename,job,mgr,hiredate,sal,nvl(comm,1),deptno
from emp
where empno=7369 or empno = 7521 or empno = 7566;
INSERT INTO DEPT1
SELECT DEPTNO, DNAME, LOC
FROM DEPT
添加其他表中的数据
UPDATE table
SET column1 = new value
WHERE column2 = old value;
添加已存在数据
UPDATE EMP2 SET ENAME =
(Select ENAME
FROM EMP
Where EMPNO=7934)
WHERE EMPNO =7934;
DELETE FROM Table WHERE Column1= Value;
一般情况下,删除时where必须存在。
否则为删除全部数据。
在上下界范围内查找
SELECT *
FROM DEPT
WHERE DEPTNO BETWEEN 5 AND 25;
在一定范围内查找
SELECT * FROM DEPT
WHERE DEPTNO IN (10,20,30);
在一定范围外查找
SELECT * FROM DEPT
WHERE DEPTNO NOT IN (10,20,30);
与操作
SELECT EMPNO, ENAME, MGR, DEPTNO
FROM EMP
WHERE EMPNO=7499
AND DEPTNO=30;
或操作
SELECT EMPNO, ENAME, MGR, DEPTNO
FROM EMP
WHERE EMPNO=7499
OR DEPTNO=30;
SELECT column1, column2
FROM table_name
WHERE column1
LIKE ‘Cond%';
通配符
SELECT column1,column2
FROM table1
WHERE condition
ORDER BY column1 [ASC| DESC],[column2 [ASC| DESC]],…
order by 按照先后顺序显示排序优先级
根据条件写出下面的查询语句:
查询EMP表的员工信息,要求满足以下条件
(1) 员工的名字以SM or SC开头
(2) 雇佣时间在1980-07-15到1987-07-15之间
(3)按照部门号升序,工资降序方式排序
(1)
SELECT * FROM emp WHERE ename like 'SM%' OR ename like 'SC%';
(2)
SELECT * FROM emp WHERE hiredate BETWEEN to_date('1980-07-15','yyyy-mm-dd') and to_date('1987-07-15','yyyy-mm-dd');
(3)
SELECT * FROM emp ORDER BY deptno,sal desc;
根据条件写出下面的查询语句:
查询EMP的员工工作(JOB)和MGR信息,要求满足以下条件
(1) 员工编号在7369和7876之间
(2)MGR的信息不重复
(1)
SELECT job,mgr FROM emp
WHERE empno
BETWEEN 7369 AND 7876;
(2)
SELECT distinct mgr,job
FROM emp WHERE empno
BETWEEN 7369 AND 7876;
多表连接时使用别名,可以
定义别名后只能使用别名。
d INNER JOIN e ON d.deptno=e.deptno
主表条件用where,从表条件可以用and
SELECT a.EMPNO
,a.ENAME
,a.DEPTNO
,b.DNAME
FROM emp a,
dept b
WHERE a.DEPTNO = b.DEPTNO
AND a.DEPTNO = 10;
SELECT a.EMPNO
,a.ENAME
,a.DEPTNO
,b.DNAME
FROM emp a
JOIN dept b
ON a.DEPTNO = b.DEPTNO
AND a.DEPTNO = 10;
SELECT a.EMPNO
,a.ENAME
,a.DEPTNO
,b.DNAME
FROM emp a
JOIN dept b
ON a.DEPTNO = b.DEPTNO
WHERE a.DEPTNO = 10;
FROM a
LEFT JOIN b
a为主表
b为从表
左外连接时保留全部主表数据,
右外连接时保留所有从表数据;
select count(*),job from emp group by job;
查询某个job的员工数。
当查询中存在group by子句时,select列表(或是having子句)中只能存在分组函数,或是出现在group by子句中的字段
select count(*),job,deptno from emp group by job,deptno order by deptno;
限制分组
select count(*),job,deptno from emp group by job,deptno having deptno>10 order by deptno;
获取EMP表中列ENAME,SAL以及MGR对应的信息,要求满足下面的条件.
(1) LOC在CHICAGO
(2) SAL在1500以上
(3)请使用下面两种方法完成
WHERE a.col1=b.col2,
a JOIN b ON a.col1=b.col2
(1)
SELECT e.ename,e.sal,e.mgr FROM emp e JOIN dept d ON e.deptno = d.deptno WHERE d.loc like 'CHICAGO' and e.sal<1500;
(2)
SELECT e.ename,e.sal,e.mgr FROM emp e,dept d WHERE e.deptno = d.deptno AND d.loc like 'CHICAGO' AND e.sal<1500;
查询员工以及对应部门的相关信息
要求:
(1)显示EMP表所有员工信息
(2)请使用LEFT JOIN和(+)两种方式完成
(1)
SELECT * FROM emp e LEFT JOIN dept d ON e.deptno=d.deptno;
(2)
SELECT * FROM emp e,dept d WHERE e.deptno=d.deptno(+);
获取(EMP表)中所有的员工及其对应的部门(DEPT表)的相关信息.
要求:
(1)员工名称中必须以大写字母A开头,并且大写字母N结尾
(2)如果对应部门不存在,则显示该部门不存在
请使用LEFT JOIN和(+)两种方式完成
(1)
SELECT e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,nvl(to_char(d.deptno),'不存在')
FROM emp e
LEFT JOIN dept d
ON e.deptno=d.deptno
WHERE e.ename LIKE 'A%N';
(2)
SELECT e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,nvl(to_char(d.deptno),'不存在')
FROM emp e,dept d
WHERE e.deptno=d.deptno AND
e.ename LIKE 'A%N';
标签:and select tran 单个字符 情况 llb like 表数据 分组
原文地址:https://www.cnblogs.com/Mr-quin/p/11280364.html