码迷,mamicode.com
首页 > 数据库 > 详细

learning-oracle-how2j

时间:2018-09-25 01:20:45      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:ike   dep   字符串拼接   employees   not   -o   row   nts   别名   

learning-oracle-how2j

 

-- 别名示例
SELECT salary*12 AS "年薪" FROM hr.employees;

-- 字符串拼接示例
SELECT first_name || ‘ ‘ || last_name AS "姓名" FROM hr.employees;

-- 消除重复行
SELECT DISTINCT department_id AS "部门号" FROM hr.employees;

-- 条件限定语句
SELECT * FROM hr.employees WHERE salary >= 20000;
SELECT * FROM hr.employees WHERE salary BETWEEN 3000 AND 4000;
SELECT * FROM hr.employees WHERE salary IN (3000,5000);
SELECT * FROM hr.employees WHERE first_name LIKE ‘%a_‘;
SELECT * FROM hr.employees WHERE department_id IS NULL;

-- 逻辑条件
SELECT * FROM hr.employees WHERE salary>=3000 AND salary<=5000;
SELECT * FROM hr.employees WHERE first_name LIKE ‘_a%‘ OR first_name LIKE ‘%a_‘;
SELECT * FROM hr.employees WHERE first_name NOT LIKE ‘%a_‘;

-- 排序查询
SELECT
e.first_name || ‘ ‘ || e.last_name AS "姓名",
e.salary AS "年薪"
FROM hr.employees e
ORDER BY e.salary DESC;

-- 关联查询
SELECT
e.first_name || ‘ ‘ || e.last_name AS "姓名",
d.department_name AS "部门名称"
FROM hr.employees e LEFT JOIN hr.departments d
ON e.department_id = d.department_id;

-- 统计查询
SELECT
AVG(salary)
FROM hr.employees;

-- 分页查询
SELECT *
FROM (
SELECT ROWNUM r,e1.*
FROM(
SELECT * FROM hr.employees e
ORDER BY e.salary DESC
)e1
)
WHERE r > 4 AND r < 11;

 

learning-oracle-how2j

标签:ike   dep   字符串拼接   employees   not   -o   row   nts   别名   

原文地址:https://www.cnblogs.com/mexding/p/9697198.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!