Home > Database > Mysql Tutorial > body text

Commonly used basic operation syntax of mysql (7) - statistical functions and group queries [command line mode]

黄舟
Release: 2017-03-03 14:16:01
Original
1643 people have browsed it

Note: All in the text. . . Represents multiple.

1. Use count to count the number of items: select count(field name...) from tablename;


2. Use avg to calculate fields The average value: select avg (field name) from tablename;


You can expand appropriately here, such as adding conditions, renaming, etc.

3. Use sum to find the sum: select sum (field name) from tablename;


4. Use max and min to find the maximum value. Minimum value:



5. Note: When using these functions, if there is no data in the database, count returns 0, otherwise Returns null;



6. Use group by to group the data: select field name. . . from tablename group by field name. . . ; You can combine grouping, sorting, statistics, etc., and the actual application is often like this:


7. Use group_concat() to implement Display the fields in each group:


8. If you want to add conditions to the group query, you must use having instead of where:


9. If you use conditional grouping and also sort, order by must be located after having:


The above is the content of mysql common basic operation syntax (7) - statistical functions and group query [command line mode]. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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