MySql will know will be (b) to read notes

Chapter VII of the data filtering

Combining WHERE clause

AND operator

SELECT prod_price,prod_name
FROM products
WHERE vend_id = 1003 AND prod_price <=10;

Here Insert Picture Description

OR operator

SELECT prod_price,prod_name
FROM products
WHERE vend_id = 1003 OR prod_price <=10;

Here Insert Picture Description

Calculation of total time

SELECT prod_price,prod_name,vend_id
FROM products
WHERE vend_id = 1003 OR vend_id = 1002 AND prod_price <=10;

Here Insert Picture Description

SELECT prod_price,prod_name,vend_id
FROM products
WHERE (vend_id = 1003 OR vend_id = 1002) AND prod_price <=10;

Here Insert Picture Description

IN operator

SELECT prod_price,prod_name,vend_id
FROM products
WHERE vend_id IN (1002,1003) 
ORDER BY prod_name;

Here Insert Picture Description

NOT operator

SELECT prod_price,prod_name,vend_id
FROM products
WHERE vend_id NOT IN (1002,1003) 
ORDER BY prod_name;

Here Insert Picture Description

Chapter VIII filtered with a wildcard

LIKE operator

  1. Wildcard: for special characters that are part of the matching value
  2. Search mode: combination of literals, or two persons to a wildcard search criteria

Percent%: Any characters appear any number of times

SELECT prod_id,prod_name
FROM products
WHERE prod_name LIKE 'jet%';

Here Insert Picture Description

_ Underscore: any single character

SELECT prod_id,prod_name
FROM products
WHERE prod_name LIKE '_ ton anvil';

Here Insert Picture Description
When using a wildcard, if not necessary, do not place the wildcard in the beginning of the search pattern

With regular expression search

Use MySQL Regular Expressions

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '1000';

Here Insert Picture Description

(.) Matches any character

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '.000';

Here Insert Picture Description

Be OR (|) match

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '1000|2000';

Here Insert Picture Description

[] Matches one of the few characters

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '[123]000';

Here Insert Picture Description

Matching range

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '[1-5] Ton';

Here Insert Picture Description

Matching special characters

SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '\\.';

Here Insert Picture Description

Metacharacters Explanation
\\f Feed
\\n Wrap
\\r Enter
\\t tabulation
\\ v Vertical tab

Examples of the plurality of matching

Metacharacters Explanation
* 0 or more matches
+ One or more matching
? Match 0 or 1
{n} Specifies the number of matches
{n, } Less than a specified number of matches
{n,m} Number matches the specified range
SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '\\([0-9] sticks?\\)';

Here Insert Picture Description

Locator

Metacharacters Explanation
^ The beginning of the text
$ End of text
[[:<;]] The beginning of the word
[[:>;]] End of a word
SELECT prod_id,prod_name
FROM products
WHERE prod_name REGEXP '^[0-9\\.]';

Here Insert Picture Description

Create calculated fields

Splicing field

Concat () splice two columns

SELECT Concat(vend_name,'(',vend_country,')')
FROM vendors
ORDER BY vend_name;

Here Insert Picture Description

RTrim () data to the right to delete extra spaces

SELECT RTrim(vend_country)
FROM vendors
ORDER BY vend_name;

The LTrim () Delete data for the left extra spaces
Trim () Delete data side two extra spaces

AS alias

Perform arithmetic calculations

SELECT 	prod_id,
				quantity,
				item_price,
				quantity*item_price AS 总价
FROM orderitems
WHERE order_num = 20005;

Here Insert Picture Description

Released five original articles · won praise 0 · Views 100

Guess you like

Origin blog.csdn.net/weixin_41246909/article/details/104458647