标签: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;
标签:sum 连表 off limit sel art inf 分组 user
原文地址:https://www.cnblogs.com/lensman/p/10160927.html