- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Fetch the size of a specific column values in MySQL and display the sum
Let us first create a table −
mysql> create table DemoTable1612 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1612 values('David','Brown'); Query OK, 1 row affected (0.75 sec) mysql> insert into DemoTable1612 values('John','Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1612 values('Bob','Taylor'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1612;
This will produce the following output −
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | David | Brown | | John | Smith | | Bob | Taylor | +-----------+----------+ 3 rows in set (0.00 sec)
Following is the query to get the size of selected rows in MySQL −
mysql> select sum(char_length(FirstName)) from DemoTable1612 where LastName IN('Brown','Smith','Taylor');
This will produce the following output −
+-----------------------------+ | sum(char_length(FirstName)) | +-----------------------------+ | 12 | +-----------------------------+ 1 row in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google