码迷,mamicode.com
首页 > 数据库 > 详细

mysql实践(六)

时间:2018-12-22 16:28:58      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:sum   连表   off   limit   sel   art   inf   分组   user   

条件:

select * from test where nid > 3;

select * from test where nid between 3 and 6;

select * from test where nid in (1,2,4,5);

select * from test where nid = 3 and name =‘eric‘;

select * from test where dept in (select department from dept);

通配符:

select * from test where name like "%eric_";

分页:

select * from test limit 5;

select * from test limit 4,5

select * from test limit 5 offset 4;

组合:

select name from userinfo union select deptment from dept;

select name from userinfo union all select deptment from dept;

排序:

select * from test order by nid asc;

select * from test order by nid desc;

select nid,name from test order by nid asc, name desc;

分组:

select dept,count(*), avg(age),max(age),min(age),sum(age) from userinfo where nid > 3 group by dept order by dept;

group by 在where之后,order by 之前

连表:

select userinfo.dept,dept.department from userinfo,dept where userinfo.dept=dept.nid;

select userinfo.*,dept.department from userinfo left join dept on userinfo.dept=dept.nid;

mysql实践(六)

标签:sum   连表   off   limit   sel   art   inf   分组   user   

原文地址:https://www.cnblogs.com/lensman/p/10160927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!