
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Finding the average and display the maximum average of duplicate ids?
For this, use AVG(). To find the maximum average value, use MAX() and group by id. Let us first create a table −
mysql> create table DemoTable -> ( -> PlayerId int, -> PlayerScore int -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1,78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(2,82); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(1,45); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(3,97); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(2,79); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+-------------+ | PlayerId | PlayerScore | +----------+-------------+ | 1 | 78 | | 2 | 82 | | 1 | 45 | | 3 | 97 | | 2 | 79 | +----------+-------------+ 5 rows in set (0.00 sec)
Here is the query to find the maximum average value for duplicate ids in MySQL −
mysql> select PlayerId from DemoTable -> group by PlayerId -> having avg(PlayerScore) > 80;
This will produce the following output −
+----------+ | PlayerId | +----------+ | 2 | | 3 | +----------+ 2 rows in set (0.00 sec)
- Related Articles
- Finding average marks of students for different subjects and display only the highest average marks in MySQL
- Find average of corresponding records (Product Price) from duplicate product ids in MYSQL
- How to get a rating average in MongoDB based on duplicate ids?
- Count duplicate ids and display the result in a separate column with MySQL
- Finding average word length of sentences - JavaScript
- Display highest amount from corresponding duplicate ids in MySQL
- Find average on the basis of corresponding duplicate VARCHAR values in MySQL
- Average Speed and Average Velocity
- Connected Load, Average Load, and Maximum Demand Load
- Finding average age from array of Objects using JavaScript
- Maximum Average Subtree in Python\n
- Maximum Average Subarray I in C++
- Maximum Average Subarray II in C++
- C++ Path with Maximum Average Value
- Calculate average of column values and display the result with no decimals in MySQL

Advertisements