sql

Group by与having理解

http://www.cnblogs.com/gaiyang/archive/2011/04/01/2002452.html

http://zhidao.baidu.com/link?url=d6esr_DT2C5a054r65NZOvEGDawJGo_4fn5KXcAJ5KppNO7eTUvNY32ziHM-EeED5f6s9UmNgKXoKBmrSlI2Ta


http://www.hackbase.com/tech/2014-10-09/69343.html


http://blog.163.com/kc_80/blog/static/54810044201210822520889/


on是过滤被联接的表的结果集
where 是过滤整个查询语句的结果集

having是对分组的结果进行过滤






http://www.cnblogs.com/gaiyang/archive/2011/04/13/2014355.html


http://www.cnblogs.com/gaiyang/archive/2011/04/13/2014356.html


distinct 是作用在 select 之后所有的列上的

select distinct id,status from shop_all; 并不是只对id去重

select id ,max(status) from shop_all group by id having count(*)>=2;


limit 是对 结果集取前n条 。如果有order by 那么先排序。


select * from user where id > ( select max(id) from ( SELECT * FROM `user` order by id limit 3) as a ) order by id limit 2
select * from user order by id limit 3, 2

你可能感兴趣的:(sql)