Home >Database >Mysql Tutorial >Detailed explanation of the use of paging queries
This time I will bring you a detailed explanation of the use of paging query, and what are the precautions for using paging query. The following is a practical case, let's take a look.
Function: Group rows according to fields
Select column, .. from table_name group by column1, column2; 使用场景:常见于统计场合,计算平均分,统计数据量等 查询每个部门的平均工资 select dept, avg(salary) from emp group by dept; 显示每个部门中的每种岗位的平均工资和最低工资 select dept, avg(salary), min(salary) from emp group by dept; select dept,job, avg(salary), min(salary) from emp group by dept,job; select dept,job, name,avg(salary), min(salary) from emp group by dept,job,name;
Use the GROUP BY clause to group the query results
select column, .. from table_name group by column having ...;
having is used Continue to filter the grouped results
The difference between where and having:
where is used to query in the original data
having is used to filter in the result set
When there is both where and having in a statement, where is executed first and then having
Where conditions cannot appear aggregationfunction, having You can
display the name of the department with an average salary lower than 6,000 and its average salary
select dept, avg(salary) from emp group by dept having avg(salary) <7000;
Paging query
select *| column, .. from table_name limit [offset] count;
offset optionally specifies from what Start getting the position
count specifies the number of data to be queried
Display the top three information
select *from emp limit 3;
Display offset(5, 8) information
select *from emp limit 5, 8;
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
Real-time search tips implemented in PHP
The above is the detailed content of Detailed explanation of the use of paging queries. For more information, please follow other related articles on the PHP Chinese website!