- 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
Sum of digits of year in MySQL?
At first, you need to extract the last digit and add the extracted value. And the same goes in till we get the sum of all digits of the year, for example, for the year 2020 −
2 + 0 + 2 + 0 = 4
The concept is as follows to extract the last digit from the year. Following is the query −
select floor(@yourVariableName % 10);
Following is the query to sum the digits of year −
mysql> set @year_column_value = 2020; Query OK, 0 rows affected (0.00 sec) mysql> select −> floor(@year_column_value / 1000) −> + floor(@year_column_value % 1000 / 100) −> + floor(@year_column_value % 100 / 10) −> + floor(@year_column_value % 10) AS SUM_OF_DIGITS_OF_YEAR;
This will produce the following output −
+-----------------------+ | SUM_OF_DIGITS_OF_YEAR | +-----------------------+ | 4 | +-----------------------+ 1 row in set (0.00 sec)
- Related Articles
- Display first two digits of year in Java (two-digit century)
- Repeated sum of Number’s digits in JavaScript
- Python | Sum of number digits in List
- Program to find minimum digits sum of deleted digits in Python
- Find smallest number with given number of digits and sum of digits in C++
- Prime digits sum of a number in JavaScript
- Calculating the sum of digits of factorial JavaScript
- Find the Largest number with given number of digits and sum of digits in C++
- Product sum difference of digits of a number in JavaScript
- Select last day of current year in MySQL?
- Finding sum of digits of a number until sum becomes single digit in C++
- Find sum of digits in factorial of a number in C++
- Get the sum of last 3 digits from all the values in a column with MySQL
- Count of n digit numbers whose sum of digits equals to given sum in C++
- Find largest sum of digits in all divisors of n in C++

Advertisements