Mysql

关注公众号 jb51net

关闭
首页 > 数据库 > Mysql > mysql完整的select语句

mysql学习笔记之完整的select语句用法实例详解

作者:随风行云

这篇文章主要介绍了mysql学习笔记之完整的select语句用法,结合实例形式详细分析了mysql select语句各种常见参数、使用方法及操作注意事项,需要的朋友可以参考下

本文实例讲述了mysql学习笔记之完整的select语句用法。分享给大家供大家参考,具体如下:

本文内容:

首发日期:2018-04-11


完整语法:

先给一下完整的语法,后面将逐一来讲解。

基础语法:select 字段列表 from 数据源;

完整语法:select 去重选项 字段列表 [as 字段别名] from 数据源 [where子句] [group by 子句] [having子句] [order by 子句] [limit子句];


去重选项::

示例:

去重前:image ,去重后image

create table student(name varchar(15),gender varchar(15));
insert into student(name,gender) values("lilei","male");
insert into student(name,gender) values("lilei","male");
select * from student;
select distinct * from student;

补充:


字段别名:

示例:

使用前:image,使用后image

create table student(name varchar(15),gender varchar(15));
insert into student(name,gender) values("lilei","male");
insert into student(name,gender) values("lilei","male");
select * from student;
select name as "姓名",gender as "性别" from student;

数据源:


where子句:

where几种语法:

补充:

select name as n ,gender from student where name ="lilei";
-- select name as n ,gender from student where n ="lilei"; --报错
select name as n ,gender from student having n ="lilei";

group by 子句:

-- 示例
select name,gender,count(name) as "组员" from student as d group by name;
select name,gender,count(name) as "组员" from student as d group by name,gender;

补充:


having子句:

-- 示例
select name as n ,gender from student having n ="lilei";
select name,gender,count(*) as "组员" from student as d group by name,gender having count(*) >2 ;-- 这里只显示记录数>2的分组

order by 子句:

-- 示例
select * from student order by name;
select * from student order by name,gender;
select * from student order by name asc,gender desc;

limit子句:

-- 示例
select * from student limit 1;
select * from student limit 3,1;
select * from student where name ="lilei" limit 1;
select * from student where name ="lilei" limit 3,1;

更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL查询技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》、《MySQL数据库锁相关技巧汇总》及《MySQL常用函数大汇总

希望本文所述对大家MySQL数据库计有所帮助。

您可能感兴趣的文章:
阅读全文