Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

1. Logical operation

And, or, notCopy the code
SELECT id, sales_A, sales_B, ((sales_A > 15) AND (sales_B > 15)) AS "double ", ((sales_A > 15) OR (Sales_B > 15)) AS "single" FROM chapter7Copy the code

result:

2. Math

Common mathematical operations include trigonometry, exponential operation, logarithm operation, round operation (round up and round down), etc. Here select a few commonly used to illustrate

2.1 Abs () calculates the absolute value

SELECT id, sales_A, sales_B, (sales_A-sales_B) as "difference ", ABS(sales_A-Sales_B) as" absolute difference "FROM chapter7Copy the code

2.2 Round up

The SELECT CEIL (2.9)Copy the code

result:

2.3 Round down

The SELECT FLOOR (2.9)Copy the code

result:

2.4 Random number generation

SELECT ID, RAND() as "random number" FROM chapter7Copy the code

result:

2.5 The specified number of digits are reserved for decimals

SELECT ROUND (1.234, 2)Copy the code

result:

Here we are reserving 2 decimal places for 1.234

2.6 Positive and negative judgment

SELECT id, sales_A, sales_B, (sales_A-sales_B) as "difference ", SIGN(sales_A-sales_B) as" positive or negative "FROM chapter7Copy the code

result:

This is the difference between sales_A and Sales_B. If the difference is positive, the result is 1; It’s negative, it’s negative 1; The difference is 0, the result is 0