Query using MySQL data in Windows (iii)

Source: Internet
Author: User

First, sort

SELECT * FROM Employees order by name;

Character-Type default character order (that is, z is always greater than a), regardless of case, if you want to sort by encoded values (that is, lowercase is always greater than uppercase), use the

SELECT * FROM Employees order by binary name;

Second, take the first n record (n in this example is 3)

SELECT * FROM Employees

ORDER BY ID

Limit 3;

Three, date Time function

1. Get the current date

Select Curdate ();

2. Take the Year

Select year (' 20140909 ');

Select year (Curdate ());

3. Take the Month

Select month (' 20140909 ');

4. Date of collection

Select DayOfMonth (' 20140909 ');

5. Get the current date and time

Select Now ();

6. Date plus minus

Select Date_add (' 20140909 ', Interval 1 month);

Description

Interval N Unit

N: Positive number indicates plus, negative number means minus

Unit: Can be Year,month,day,hour,minute,second,week

Four, arithmetic operations

1. Modulo Operation 5%2

Select mod (5,2);

Five, pattern matching

1. Wildcard characters, using like or not

% All characters

_ One character

2. Regular expressions, using RegExp (rlike) or not regexp (not rlike)

. Match any single character

[] matches any character in square brackets

* Match 0 or more characters in front of it

{n} where n represents a number, the number of characters before it is repeated

^ Mode start

$ pattern End

SELECT * FROM employees where name RegExp ' ^b ' matches names starting with B

SELECT * FROM employees where name regexp binary ' ^b ' matches only lowercase letter B First Name

Vi. using User variables (in this case @name as variable names)

Select @name: =name from Employees where id=1;

Select @name;

 

  

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.