Get the App
SLTechnology News&Howtos  ›  Database  › 

The usage of paging query in mysql Database

Shulou Source: shulou.com Published: 2022-05-31 23:50:37 09月15日 Update

This article is about the use of paging queries in mysql databases. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Purpose: to group rows by field

Select column,.. From table_name group by column1, column2; usage scenarios: commonly used in statistical situations, calculating average scores, statistical data, etc. Query the average salary of each department select dept, avg (salary) from emp group by dept; shows the average wage and minimum wage of each post in each department 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 results of a query

Select column,.. From table_name group by column having...

Having is used to continue filtering the grouping results.

The difference between where and having:

Where is used to query in raw data

Having is used to filter in the result set

When there are both where and having in a statement, execute where first and then having

Aggregate functions cannot appear in Where conditions, but can be found in having.

Show the name of the department whose average salary is less than 6000 and his average salary

Select dept, avg (salary) from emp group by dept having avg (salary)

Tags: Query data salary result department grouping usage database method middle score information content more article statistics good original practical lowest location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Shulou Tech Info Linux Xiaomi