Home > Database > Mysql Tutorial > Detailed explanation of the use of paging queries

Detailed explanation of the use of paging queries

php中世界最好的语言
Release: 2018-03-26 09:37:03
Original
2978 people have browsed it

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;
Copy after login

Use the GROUP BY clause to group the query results

select column, .. from table_name group by column having ...;
Copy after login

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;
Copy after login

Paging query

select *| column, .. from table_name limit [offset] count;
Copy after login

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;
Copy after login

Display offset(5, 8) information

select *from emp limit 5, 8;
Copy after login

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

Generate intricate (tilted, sinusoidal interference lines, sticky Paste, rotate to verify) verification code

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template