- 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
How can I find the percentage of my users whose birth date is between 1980 and 1996 in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> DateOfBirth varchar(100) -> ); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019/01/31'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('1980/02/01'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('1985/04/10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('1995/06/04'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('1990/12/24'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('1996/11/04'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-------------+ | DateOfBirth | +-------------+ | 2019/01/31 | | 1980/02/01 | | 1985/04/10 | | 1995/06/04 | | 1990/12/24 | | 1996/11/04 | +-------------+ 6 rows in set (0.00 sec)
Following is the query to find the percentage of users with birth date between 1980 and 1996 −
mysql> SELECT Sum(DateOfBirth BETWEEN '1980/01/01' AND '1996/12/31') * 100 / Count(*) as Percentage from DemoTable;
Output
+------------+ | Percentage | +------------+ | 83.3333 | +------------+ 1 row in set (0.00 sec)
- Related Articles
- How can we find the employees from MySQL table whose age is greater than say 30 years, providing the only date of birth on the table?
- Calculate age from date of birth in MySQL?
- How can I the date of creation and updation of tables in MySQL?
- How can I make the balance between my best friend and lover?
- How to find the age when date of birth is known? Using Java?
- How to can I get the names of my MySQL table columns?
- Calculate age based on date of birth in MySQL?
- Calculate Age from given Date of Birth in MySQL?
- MySQL query to get the dates between range of records displaying student’s Date of Birth?
- How can I replace & with an ampersand in my MySQL database?
- How to display the day name on the basis of Date of Birth records in MySQL?
- How can I calculate the total value of products from my MySQL product table?
- How can I use any character, at the place of space, in MySQL TIMESTAMP to distinguish between date and time parts?
- Can I write my own MySQL functions to use in MySQL queries?
- How can I enhance my select query to make it faster in MySQL?

Advertisements