Advanced 2: Conditions inquiry

Advanced # 2: Conditional Query
/ *

Syntax:
the SELECT
list of queries
from
table name
where
the filter criteria;

Classification:
a, conditional Expression Filter

simple conditional operators:> <! = = <>> = <=

Two, a logical expression screening
logical operators:
action: conditional expressions for connecting
&& ||!
And or Not

&& and and: both conditions are true, the result is true, false otherwise
|| or or: as long as one condition is true, the result is true, otherwise it is false
or not:! If the condition of the connection itself is false, evaluates to true, false otherwise

three fuzzy query
like
the BETWEEN and
in
iS null

* /
# a, conditional expression screening

Case # 1: Employee Information Query salary> 12000

The SELECT
*
the FROM
the Employees
the WHERE
salary> 12000;


# Case 2: Query department number is not equal to the employee name and department number of 90 numbers
the SELECT
last_name,
department_id
the FROM
the Employees
the WHERE
department_id <> 90;


# Second, the logical expression screening

Case # 1: Query z employee wages were between 10,000 to 20,000, wages and bonuses
the SELECT
last_name,
salary,
commission_pct
the FROM
the Employees
the WHERE
salary> = 10000 the AND salary <= 20000;
# Case 2: Query department number is not in the 90 to between 110 or higher employee payroll information 15000
the SELECT
*
the FROM
the employees
the WHERE
the NOT (DEPARTMENT_ID> = 90 DEPARTMENT_ID the AND <= 110) oR the salary> 15000;
# three fuzzy query
/ *
like

between and
in
is null|is not null

* /
# 1.like
/ *
Features:
① general and wildcards used with
wildcards:
% any number of characters, characters comprising 0
_ any single character
*,

Case # 1: The query employee information employee name contains characters of a

the SELECT
*
from
the Employees
the WHERE
last_name like '% a%'; abc #
# Case 2: Query the employees name the third character is e, the fifth character is a wage employee name and
the SELECT
last_name,
salary
the FROM
the Employees
the WHERE
last_name the LIKE ' __n_a% ';

 

Case # 3: The second query employee names for the characters _ employees name

#ESCAPE escape character

The SELECT
last_name
the FROM
the Employees
the WHERE
last_name the LIKE '_ $ _%' the ESCAPE '$';
# 2.between and
/ *
① can increase use between and conciseness statement
② threshold comprises
sequentially ③ two critical values do not interchange

*/


Case # 1: Query employee numbers between 100-120 employee information

SELECT
*
FROM
employees
WHERE
employee_id >= 120 AND employee_id<=100;
#----------------------
SELECT
*
FROM
employees
WHERE
employee_id BETWEEN 120 AND 100;

3.In #
/ *
Meaning: to determine whether the value of a field of an item in the list of
features:
① use in improving concise statement of the
value of the type ②in lists have the same or compatible
③in list does not support wildcard

* /
# Case: inquiry staff jobs number is a staff name and number types IT_PROG, AD_VP, AD_PRES in

SELECT
last_name,
job_id
FROM
employees
WHERE
job_id = 'IT_PROT' OR job_id = 'AD_VP' OR JOB_ID ='AD_PRES';


#------------------

SELECT
last_name,
job_id
FROM
employees
WHERE
job_id IN( 'IT_PROT' ,'AD_VP','AD_PRES');

. 4 #, is null
/ *
= or <> is not available for determining a null value
is null or is not null null value based

*/

Case # 1: The query does not name the staff bonus and bonus rate
the SELECT
last_name,
commission_pct
the FROM
the Employees
the WHERE
commission_pct IS NULL;


Case # 1: There are bonuses of employees query name and bonuses of
the SELECT
last_name,
commission_pct
the FROM
the Employees
the WHERE
commission_pct the NOT IS NULL;

The following is ---------- # ×
the SELECT
last_name,
a commission_pct
the FROM
the Employees

The WHERE
salary IS 12000;


# equal security <=>


Case # 1: The query does not name the staff bonus and bonus rate
the SELECT
last_name,
commission_pct
the FROM
the Employees
the WHERE
commission_pct <=> NULL;


# Case 2: Query salary information for employees 12,000
the SELECT
last_name,
salary
the FROM
the Employees

WHERE
salary <=> 12000;

#is null pk <=>

The IS NULL: NULL values can only be determined, higher readability recommended
<=>: NULL value may be determined, and based on normal values, lower readability

 

Guess you like

Origin www.cnblogs.com/Diyo/p/11318663.html