MySQL—基本概念与查询

2019-01-22  本文已影响0人  d93c0d3b5051

数据库基本概念

数据库查询

SELECT employee_id, first_name, last_name,department_id 
FROM employees 
WHERE department_id >= 90
where子句的使用.png
注: 比较运算符与逻辑运算符
比较运算符01.png
比较运算符02.png
逻辑运算符.png
  1. BETWEEN ... AND ...
    SELECT last_name, salary FROM employees WHERE salary BETWEEN 2500 AND 3500
    between.png
  2. IN
SELECT employee_id, last_name,salary,manager_id 
FROM employees 
WHERE manager_id IN (100,101,102)
IN.png
  1. LIKE 模糊查询, %代表任意个字符, _代表一个字符
    SELECT first_name FROM employees WHERE first_name LIKE '_O%'
    %.png
  2. IS (NOT) NULL 判断是否为空值
    SELECT last_name, manager_id FROM employees WHERE manager_id IS NULL
    NUll.png
  3. AND
    SELECT employee_id, last_name, job_id,salary FROM employees WHERE salary >=100 AND job_id LIKE '%MAN'
    AND.png
  4. OR
SELECT employee_id, last_name, job_id,salary 
FROM employees 
WHERE salary >=100 OR job_id LIKE '%MAN'
OR.png
SELECT beauty.id, `name`, boyName 
FROM beauty, boys 
WHERE beauty.boyfriend_id = boys.id
等值链接.png
注: 在表中有相同的列名时,在列名之前加上表名前缀进行区分。也可以使用表的别名加列名,表的别名.列名
  1. ON子句创建多表链接
SELECT beauty.id, `name`, boyName
FROM beauty INNER JOIN boys
ON beauty.boyfriend_id = boys.id
ON.png
  1. Join链接再叙。。。
上一篇下一篇

猜你喜欢

热点阅读