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)!