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

MySQL 8.0.21 installation and configuration method graphic tutorial

Record the installation and configuration method ...

Detailed explanation of the usage of Object.assign() in ES6

Table of contents 2. Purpose 2.1 Adding propertie...

React configuration px conversion rem method

Install related dependencies npm i lib-flexible -...

Implementation of CSS linear gradient concave rectangle transition effect

This article discusses the difficulties and ideas...

MySQL controls the number of attempts to enter incorrect passwords

1. How to monitor MySQL deadlocks in production e...

Optimal web page width and its compatible implementation method

1. When designing a web page, determining the widt...

JavaScript implements select all and unselect all operations

This article shares the specific code for JavaScr...

How to build a standardized vmware image for kubernetes under rancher

When learning kubernetes, we need to practice in ...

Implementing timed page refresh or redirect based on meta

Use meta to implement timed refresh or jump of th...

Some slightly more complex usage example codes in mysql

Preface I believe that the syntax of MySQL is not...

Methods for deploying MySQL services in Docker and the pitfalls encountered

I have been learning porters recently. I feel lik...

JavaScript lazy loading detailed explanation

Table of contents Lazy Loading CSS styles: HTML p...

Tomcat maxPostSize setting implementation process analysis

1. Why set maxPostSize? The tomcat container has ...

80 lines of code to write a Webpack plugin and publish it to npm

1. Introduction I have been studying the principl...

Detailed tutorial on downloading mysql on Windows 10

MySQL versions are divided into Enterprise Editio...