这篇文章主要讲解了mysql中完整的select语句的用法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
完整语法:
先给一下完整的语法,后面将逐一来讲解。
基础语法:select 字段列表 from 数据源;
完整语法:select 去重选项 字段列表 [as 字段别名] from 数据源 [where子句] [group by 子句] [having子句] [order by 子句] [limit子句];
示例:
去重前: ,去重后
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;
示例:
使用前:,使用后
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;
-- 示例 select name from (select * from student) as d;
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";
-- 示例 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;
-- 示例 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的分组
-- 示例 select * from student order by name; select * from student order by name,gender; select * from student order by name asc,gender desc;
-- 示例 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中完整的select语句的用法有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。