MySQL Common statements 2

Source: Internet
Author: User

A lot of MySQL statements don't remember when they're used, so let's take a simple example.

/*
SQLyog Enterprise Edition-MySQL GUI v8.14
Mysql-5.1.49-community
*********************************************************************
*/
/*!40101 SET NAMES UTF8 */;

CREATE TABLE ' T_student ' (
' ID ' double,
' Stuname ' varchar (60),
' Age ' double,
' Sex ' varchar (30),
' Gradename ' varchar (60)
);
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 1 ', ' Zhang San ', ' 23 ', ' Male ', ' first grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 2 ', ' Zhang Sanfeng ', ' 25 ', ' Male ', ' sophomore ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 3 ', ' John Doe ', ' 23 ', ' Male ', ' first grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 4 ', ' Harry ', ' 22 ', ' Male ', ' third grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 5 ', ' Jenny ', ' 21 ', ' Female ', ' first grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 6 ', ' Li Na ', ' 26 ', ' Female ', ' sophomore ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 7 ', ' Wang Feng ', ' 20 ', ' Male ', ' third grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 8 ', ' Mona ', ' 21 ', ' Female ', ' sophomore ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 9 ', ' small black ', ' 22 ', ' Male ', ' first grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 10 ', ' herd ', ' 25 ', ' Male ', ' sophomore ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 11 ', ' Little Zhang San ', ' + ', NULL, ' second grade ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 12 ', ' small Zhang San ', ' 23 ', ' Male ', ' sophomore ');
Insert INTO ' t_student ' (' IDs ', ' stuname ', ' age ', ' sex ', ' gradename ') VALUES (' 13 ', ' Zhang Sanfeng ', ' "'", ' ", ') ', ' the ' second Grade ');


SELECT id,stuname,age,sex,gradename from T_student;

SELECT stuname,id,age,sex,gradename from T_student;

SELECT * from T_student;

SELECT stuname,gradename from T_student;

SELECT * from T_student WHERE id=1;

SELECT * from T_student WHERE age>22;

SELECT * from T_student WHERE age in (21,23);
SELECT * from T_student WHERE age is not in (21,23);

SELECT * from T_student WHERE age between and 24;
SELECT * from T_student WHERE age not between and 24;

SELECT * from t_student WHERE stuname like ' Zhang San ';
SELECT * from t_student WHERE stuname like ' Zhang San% ';
SELECT * from t_student WHERE stuname like ' Zhang San __ ';
SELECT * from t_student WHERE stuname like '% Zhang San% ';

SELECT * from t_student WHERE sex is NULL;
SELECT * from t_student WHERE sex is not NULL;

SELECT * from T_student WHERE gradename= ' first grade ' and age=23
SELECT * from T_student WHERE gradename= ' first grade ' OR age=23

SELECT DISTINCT gradename from T_student;

SELECT * from T_student ORDER by age ASC;
SELECT * from T_student ORDER by age DESC;

SELECT * from T_student GROUP by Gradename;

SELECT Gradename,group_concat (stuname) from T_student GROUP by Gradename;

SELECT Gradename,count (stuname) from T_student GROUP by Gradename;

SELECT Gradename,count (stuname) from T_student GROUP by Gradename have COUNT (stuname) >3;

SELECT Gradename,count (stuname) from T_student GROUP by Gradename with ROLLUP;
SELECT Gradename,group_concat (stuname) from T_student GROUP by Gradename with ROLLUP;

SELECT * from T_student LIMIT 0, 5;
SELECT * from T_student LIMIT 5, 5;
SELECT * from T_student LIMIT 10, 5;

MySQL Common statements 2

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.