赞
踩
目录
子查询类型
使用ANY运算符
使用ALL运算符
子查询中的空值
- SELECT
- e1.LAST_NAME,e1.HIRE_DATE
- FROM employees e1
- where e1.DEPARTMENT_ID = (select e.DEPARTMENT_ID FROM employees e
- where e.LAST_NAME ='Zlotkey') AND e1.LAST_NAME <> 'Zlotkey';
- SELECT
- e1.EMPLOYEE_ID,e1.LAST_NAME
- FROM employees e1
- WHERE e1.SALARY > (select AVG(e.SALARY) from employees e) ORDER BY e1.SALARY;
- SELECT
- e1.EMPLOYEE_ID,e1.LAST_NAME
- FROM employees e1
- WHERE e1.DEPARTMENT_ID IN
- (SELECT e.DEPARTMENT_ID FROM employees e
- WHERE e.LAST_NAME like '%u%')
- SELECT
- e.LAST_NAME,e.DEPARTMENT_ID,e.JOB_ID
- FROM employees e
- WHERE e.DEPARTMENT_ID IN
- (SELECT
- d.DEPARTMENT_ID
- FROM departments d
- WHERE d.LOCATION_ID = 1700)
- SELECT
- e1.LAST_NAME,e1.SALARY
- FROM employees e1
- where e1.MANAGER_ID IN
- (select e.EMPLOYEE_ID from employees e where
- e.LAST_NAME ='King')
- SELECT
- e.DEPARTMENT_ID,e.LAST_NAME,e.JOB_ID
- FROM employees e
- WHERE e.DEPARTMENT_ID = (select d.DEPARTMENT_ID FROM departments d
- WHERE d.DEPARTMENT_NAME = 'Executive');
MySQL中的索引
查询索引
SHOW INDEX FROM table_name;
直接创建索引
示例:为 emp3 表中的 name 创建一个索引,索引名为emp3_name_index;
示例:
DROP INDEX indexname ON tablename;
drop index emp3_address_index on emp3;
创建唯一索引
修改表添加唯一索引
创建表时指定唯一索引
添加了主键约束就有了主键索引。
创建表时指定主键索引
添加组合索引
创建表时创建组合索引
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。