MySQL Query statement

Source: Internet
Author: User
Tags mysql query

Select field 1, Field 2 from Table 1, table 2 where field group by Group Field having field order by field asc| DESC Limit M,n

First, to inquire all

Select *  from student;
Select  as  from student;
Select  from student;

Second, the conditions of inquiry

1. Query student ID equals 1

*  from where student_id;

2. Query the Name field NULL

*  from where  is null;

3. Query the name field is not NULL

Select *  from where  is  not null;

4. Query the Name field is an empty string

Select *  from where = ";

5. Query the Name field is not an empty string and is not NULL

Select *  from where != ";

6. Query the city character Gencun data in Henan province and Shandong Province

Select *  from where inch (' Shandong province ',' Henan province ');

7. Query age from 25 to 30

Select *  from where between  -  and ;

8. Query that age is not between 20 and 30

Select *  from where  not between  -  and ;

9. Query the first word is Guo's data

Select *  from where  like ' Guo% ';

10 Query The first word is Guo's two characters of data

Select *  from where  like ' Guo _ ';

11 Query the existence of Guo's Word data

Select *  from where  like ' % Guo ';

Third, group query

1. Group Sex

Select Sex,count(*fromgroup by sex;

2. Group sex Pre-condition query

Select Sex,count(*fromwhere!=' Li Bai  'group by sex;

3. Group Sex after conditional query

Select Sex,count(*fromgroupby hascount (*)>5;

4. Group after query and then condition query

Select Sex,count(*fromwhere!=' li Bai '  Groupby hascount(*)>5;

Four, sort query

1. Descending sort

Select *  from Order  by desc;

2. Descending and Ascending sort

Select *  from Order  by desc ASC;

Five, aggregate function

Count (*) sum (Salary) avg (Salary) min (Salary) Max (Salary)

MySQL Query statement

Related Article

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.