Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MySQL Returns for Single Value in Compound INTERVAL Unit



In this case, MySQL will take into consideration right most unit given in compound INTERVAL unit. It will return the output after calculating the interval on the basis of single value provided in the enclosed set of unit values. The following example will clarify it −

mysql> Select TIMESTAMP('2017-10-22 04:05:36' + INTERVAL '2 ' year_month) AS 'Only Month Value Changed';
+--------------------------+
| Only Month Value Changed |
+--------------------------+
| 2017-12-22 04:05:36      |
+--------------------------+
1 row in set (0.00 sec)

The query above changes the month (right most in compound INTERVAL unit) from 10 to 12 based on the single value i.e. 2 provided in the enclosed set of unit values.

Updated on: 2020-01-30T05:20:18+05:30

91 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements