Calculation years
If you want to calculate the person's age by birthday, you can use the following statement:
SELECT DATE_FORMAT (FROM_DAYS (TO_DAYS (now ()-TO_DAYS (@ dateofbirth), '% y') + 0;
2. Difference between two time points
Returns the difference between two datetime values. Assume that dt1 and dt2 are of the datetime type and are in the format of 'yyyy-mm-dd hh: mm: ss'. The difference between them is in the number of seconds: UNIX_TIMESTAMP (dt2) -UNIX_TIMESTAMP (dt1) divided by 60 is the number of minutes in the difference, divided by 3600 is the number of hours in the difference, and then divided by 24 is the number of days in the difference.
3. display the value of a column that appears N times
The Code is as follows:
SELECT id
FROM tbl
Group by id
Having count (*) = N;
4. Calculate the workdays between two days
Workdays are divided into Saturday and Sunday holidays.
The Code is as follows:
Select count (*)
FROM calendar
WHERE d BETWEEN Start AND Stop
And dayofweek (d) not in (1, 7)
AND holiday = 0;