Mysql aggregate function nested use operation

Mysql aggregate function nested use operation

Purpose: Nested use of MySQL aggregate functions

Aggregate functions cannot be nested directly, for example: max(count(*))

But you can use nested subqueries, eg:

Note: The following as must be written

select max(total) from ( select count(*) as total from blog group by btype) as aa;

Supplementary knowledge: Tips for using the MAX() and count() functions in MySQL

1. max() function

In the case of considering improving database IO, you can create an index ===> create index index name on table name (column name);

2. count() function

Question: count(*) and count(column)

* Includes null data in the table

Tips: You can use this feature of count(*) to process instances that are counted according to different conditions:

For example:

Query the number of movies in 2006 and 2007 in one SQL statement ===>select count(release_year='2006' or null ) as 'Number of movies in 2006', count(release_year='2007' or null ) as 'Number of movies in 2007' from movies;

The above article on nested use of MySQL aggregate functions is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL grouping queries and aggregate functions
  • MySQL uses aggregate functions to query a single table
  • Analysis of MySQL query sorting and query aggregation function usage
  • How to add conditional expressions to aggregate functions in MySql
  • MySQL aggregate function sorting

<<:  10 Best Practices for Building and Maintaining Large-Scale Vue.js Projects

>>:  Complete steps for using Nginx+Tomcat for load balancing under Windows

Recommend

Detailed installation tutorial of mysql 5.7 under CentOS 6 and 7

You always need data for development. As a server...

MySQL 8.0.17 installation and usage tutorial diagram

Written in front In the past and in the current p...

Why is the scroll bar on the web page set on the right?

Why are the scroll bars of the browsers and word ...

How to use translate and transition in CSS3

I always feel that translate and transition are v...

How complicated is the priority of CSS styles?

Last night, I was looking at an interview question...

Django online deployment method of Apache

environment: 1. Windows Server 2016 Datacenter 64...

How to implement Vue timer

This article example shares the specific code of ...

Detailed explanation of Vue slot

1. Function : Allows the parent component to inse...

Sample code for converting video using ffmpeg command line

Before starting the main text of this article, yo...

Implementation of element shuttle frame performance optimization

Table of contents background Solution New Questio...

How to display small icons in the browser title bar of HTML webpage

Just like this effect, the method is also very si...