MySQL implements increasing or decreasing the specified time interval for all times in the current data table (recommended)

MySQL implements increasing or decreasing the specified time interval for all times in the current data table (recommended)

The DATE_ADD() function adds a specified time interval to a date.

All data in the current table will be incremented by one day:

UPDATE ACT_BlockNum SET CreateTime = DATE_ADD(CreateTime, INTERVAL 1 DAY);

All data in the current table is reduced by one day:

UPDATE ACT_BlockNum SET CreateTime = DATE_ADD(CreateTime, INTERVAL -1 DAY);

In order to prevent the database query from reporting an empty exception, when the query result is returned as an integer, it can be compared with 0. If it is empty, a 0 is returned to the customer, otherwise the result value of the query is returned. The sql is as follows

 SELECT IFNULL(SUM(Num),0) from DPEvent.ACT_BlockNum where CreateTime BETWEEN #startTime# AND #endTime#;
MYSQL IFNULL(expr1,expr2)

If expr1 is not NULL, IFNULL() returns expr1, otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used. Similar ones
isnull(expr)

If expr is null, then isnull() returns 1, otherwise it returns 0.

The update statement updates the values ​​of multiple fields

update @A 
set c1=b.c1 ,c2=b.c2,c3=b.c3
from @A a,@B b where a.id=2 and b.id=6
update A
  set (A.a2,A.a3) =(select B.b2,b.b3
  from B
  where B.b1= A.a1 and A.a3=100
  )

The above is what I introduced to you about MySQL to increase or decrease all the time in the current data table by a specified time interval. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • How to use MySQL DATEDIFF function to get the time interval between two dates
  • Example analysis of interval calculation of mysql date and time
  • MySQL DATE_ADD and ADDDATE functions add a specified time interval to a date

<<:  How to bind domain name to nginx service

>>:  A brief summary of vue keep-alive

Recommend

wget downloads the entire website (whole subdirectory) or a specific directory

Use wget command to download the entire subdirect...

MySQL 8.0.12 Quick Installation Tutorial

The installation of MySQL 8.0.12 took two days an...

Vue implements the browser-side code scanning function

background Not long ago, I made a function about ...

GET POST Differences

1. Get is used to obtain data from the server, wh...

jQuery implements simple pop-up window effect

This article shares the specific code of jQuery t...

Linux disk sequential writing and random writing methods

1. Introduction ● Random writing will cause the h...

Summary of Mathematical Symbols in Unicode

There are many special symbols used in mathematic...

Several practical scenarios for implementing the replace function in MySQL

REPLACE Syntax REPLACE(String,from_str,to_str) Th...

What should I do if I can't view the source file of a web page?

Q: Whether using Outlook or IE, when you right-cl...

Best Practices Guide for MySQL Partitioned Tables

Preface: Partitioning is a table design pattern. ...

Implementation of nacos1.3.0 built with docker

1. Resume nacos database Database name nacos_conf...

Let’s talk in detail about how browsers view closures

Table of contents Preface Introduction to Closure...

MySQL functional index optimization solution

When using MySQL, many developers often perform f...