当前位置:网站首页>Condition query

Condition query

2022-06-26 04:38:00 Lili demon_


grammar :SELECT Query list FROM Table name WHERE filter ;

  1. Filter by conditional expression
    Simple conditional operators :<>= (!=<>) >=<=
  2. Filter by logical expression
    Logical operators : ANDORNOT
  3. Fuzzy query
    LIKEBETWEEN ANDINIS NULL

Filter by conditional expression

#1.  Query salary  > 12000  Employee information 
SELECT * FROM employees WHERE salary > 12000;

#2.  Query department number is not equal to  90  Employee name and department number of 
SELECT
	CONCAT(last_name, " ", first_name) AS  Employee name ,
	department_id
FROM
	employees
WHERE
	department_id <> 90; #  It's not equal to 

Filter by logical expression

AND

#1.  Check salary at  10000  To  20000  Between the employee's name , Salaries and bonuses 
SELECT
	CONCAT(last_name, " ", first_name) AS  Employee name ,
	salary,
	commission_pct
FROM
	employees
WHERE
	salary >= 10000
AND salary <= 20000;

OR / NOT

#2.  The inquiry department number is not in  90  To  110  Between , Or pay more than  15000  Employee information 
SELECT
	*
FROM
	employees
WHERE
	NOT (department_id >= 90 AND department_id <= 110)
    OR salary > 15000;

Fuzzy query

LIKE

  • Generally used with wildcards
  • wildcard :%: Any number of characters ,_: Any single character
#1.  Query employee name contains characters “a” Employee information 
SELECT * FROM employees WHERE last_name LIKE "%a%";

#2.  The third character in the query employee name is "n", The fifth character is "l" The name and salary of the employee 
SELECT last_name,salary 
FROM employees where last_name LIKE "__n_l%";

#3.  The second character in the employee name is “_” Employee name of 
# ( Use escape characters  \  or   Any character   Use  ESCAPE)
SELECT last_name 
FROM employees WHERE last_name LIKE "_$_%" ESCAPE "$";

BETWEEN AND

  • Including left and right critical values
#1.  Query the employee number in  100  To  120  Employee information between 
SELECT * FROM employees WHERE employee_id BETWEEN 100 AND 120;

IN

#1.  The job number of the employee is  AD_VP,IT_PROG,AD_PRES The name and job number of one of the employees in 
SELECT
	last_name,
	job_id
FROM
	employees
WHERE
	job_id IN (
		"AD_VP",
		"IT_PROG",
		"AD_PRES");

IS NULL and IS NOT NULL

#1.  Query the employee name and bonus rate without bonus 
SELECT last_name,commission_pct 
FROM employees WHERE commission_pct IS NULL;

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

<=>: Safety is equal to

  • Can be judged NULL and Common value
SELECT last_name,commission_pct 
FROM employees WHERE commission_pct <=> NULL;
原网站

版权声明
本文为[Lili demon_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260428040315.html