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

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

黄舟
黄舟Original
2017-03-03 14:16:011511browse

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 (m.sbmmt.com)!


Statement:
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