Arithmetic operator: + – * / div % mod

In SQL, + has no join function and represents addition. At this point, the string is converted to a numeric value (implicit conversion)

2. Compare operators

2.1 = <=> <> != < <= > >=

2.2

  1. IS NULL \ IS NOT NULL \ ISNULL
  2. LEAST() \ GREATEST
  3. BETWEEN condition 1, lower bound 1 AND condition 2, upper bound 2
  4. in (set)\ not in (set)
  5. LIKE: fuzzy query. _ : indicates an uncertain character
    • % : Matches 0 or more characters.
    • “_” : only one character can be matched.

    ESCAPE character: ESCAPE ‘$’ or \…

  6. REGEXP \ RLIKE: regular expression

3. The logical operators: the OR | | AND && NOT! XOR

4. Operator: & | ^ ~ > > < <

————————————————————

practice

1. Select the names and salaries of employees whose salaries do not range from 5000 to 12000

SELECT last_name,salary
FROM employees
#where salary not between 5000 and 12000;
WHERE salary < 5000 OR salary > 12000;
Copy the code

2. Select the name and department number of the employee working in department 20 or 50

SELECT last_name,department_id
FROM employees
//# where department_id in (20,50);
WHERE department_id = 20 OR department_id = 50;
Copy the code

3. Select the name and job_id of an employee who has no manager

SELECT last_name,job_id,manager_id
FROM employees
WHERE manager_id IS NULL;

SELECT last_name,job_id,manager_id
FROM employees
WHERE manager_id <=> NULL;
Copy the code

4. Select the names, salaries and bonus levels of employees in the company who will receive bonuses

SELECT last_name,salary,commission_pct
FROM employees
WHERE commission_pct IS NOT NULL;


SELECT last_name,salary,commission_pct
FROM employees
WHERE NOT commission_pct <=> NULL;
Copy the code

5. Select the employee whose name starts with a

SELECT last_name
FROM employees
WHERE last_name LIKE '__a%';
Copy the code

6. Select the employee whose name contains the letters A and K

SELECT last_name
FROM employees
WHERE last_name LIKE '%a%k%' OR last_name LIKE '%k%a%';
//#where last_name like '%a%' and last_name LIKE '%k%';
Copy the code

Select * from employees where first_name ends in ‘e’

SELECT first_name,last_name
FROM employees
WHERE first_name LIKE '%e';

SELECT first_name,last_name
FROM employees
WHERE first_name REGEXP 'e$'; # begins with e:'^e'
Copy the code

8. Display the name and type of the employees department whose id is between 80 and 100

SELECT last_name,job_id FROM employees #1: Recommend WHERE department_id BETWEEN80 AND 100; # way2: Recommendation, and way1Same #where department_id >=80 and department_id <= 100; # way3Only in this case. #where department_idin (80.90.100);

SELECT * FROM departments;
Copy the code

Select * from employees where manager_id = 100,101,110

SELECT last_name,salary,manager_id
FROM employees
WHERE manager_id IN (100.101.110);
Copy the code