- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find average on the basis of corresponding duplicate VARCHAR values in MySQL
Let us first create a table −
mysql> create table DemoTable( Value int, Value2 varchar(100) ); Query OK, 0 rows affected (0.84 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10,'999.999.999.999'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(20,'888.888.888.888'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(30,'999.999.999.999'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+-----------------+ | Value | Value2 | +-------+-----------------+ | 10 | 999.999.999.999 | | 20 | 888.888.888.888 | | 30 | 999.999.999.999 | +-------+-----------------+ 3 rows in set (0.00 sec)
Here is the query to find average on the basis of corresponding VARCHAR records::
mysql> select Value2,avg(Value) from DemoTable group by Value2;
This will produce the following output −
+-----------------+------------+ | Value2 | avg(Value) | +-----------------+------------+ | 999.999.999.999 | 20.0000 | | 888.888.888.888 | 20.0000 | +-----------------+------------+ 2 rows in set (0.06 sec)
- Related Articles
- Find average of corresponding records (Product Price) from duplicate product ids in MYSQL
- How to concatenate columns based on corresponding duplicate id values in MySQL? Display the duplicate values in the same column separated by slash
- How to add duplicate varchar values without displaying error in MySQL?
- MySQL query to select three highest values and sort alphabetically on the basis of corresponding column with name
- Add records from corresponding duplicate values in another column with MySQL
- MySQL query to fetch the maximum corresponding value from duplicate column values
- Match column values on the basis of the other two column values in MySQL
- MySQL query to group concat and place data into a single row on the basis of 1 values in corresponding column?
- SUM corresponding duplicate records in MySQL
- Concatenate rows on the basis of boolean values in another column with MySQL
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- Find the average of column values in MySQL using aggregate function
- Perform MySQL SELECT on dates inserted into the table as VARCHAR values
- How to combine duplicate values into one with corresponding value separated by hyphens in MySQL?

Advertisements