MySQL Advanced 3456

Source: Internet
Author: User

Sort queries

First, the grammar

Select query table

From table

Where filter criteria

Order by sorted list [Asc/desc]

Characteristics:

1. ASC: Ascending

Desc: Descending

2. Support single field, multiple fields, functions, expressions, aliases in sorted list

3. The position of order by is generally placed at the end of the query statement (except limit)

Common functions:

Features: Improved reusability

Hides the implementation details

Call function Syntax:

Select function name (argument list);

Second, single-line function

1. Character functions

Concat: Connect

SUBSTR: Intercepting strings

Upper/lower: Uppercase, lowercase

Repalce: Replace

Length: Gets the byte length

Trim: Go space before and after

Lpad/rpad: padding left and right

InStr: Gets the index of the first occurrence of a string

2. Mathematical functions

Ceil: Rounding up

Round: Rounding

MoD: Rounding

Floor: Rounding Down

Truncat: Stage

Rand: Get random number

3. Date function

Date

Now

Year

Month

Day

Date_format:

Curdate:

Str_to_date:

Curtime:

Hour

Minute

Second

DateDiff: Two days of difference in time

MonthName

  

  

4. Other functions

Wersion: Database server version

Database: currently open databases

Password: Returns the password form for this character

MD5: Returns the MD5 encryption form of the character

5. Process Control function

if (conditional expression, expression 1, expression 2): Returns 1 if the conditional expression is true, 2 otherwise

Case Scenario 1

Case variable or expression or field

When constant 1 then value 1

When ....

else ...

End

Case Scenario 2

  

Case

When condition 1 then value 1

When ....

else ...

End

Third, grouping functions

1. Classification

Max: Max value

Min: Minimum value

Avg: Average

Sum: Sum

Count: Count

2. Features

1. Grammar

Select Max (field) from table name

2. Supported types

Sum and AVG are generally used to handle numeric types

Max, Min, Cuount can handle any data type

All of the above grouping functions ignore null

Can be used with distinct, to achieve de-re-statistics

Count function

Conut (field): Counts the number of non-null values in the field

COUNT (*): Number of rows in the statistic result set

Case: Query the number of employees in each department

MySQL Advanced 3456

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.