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

How to implement image mapping with CSS

1. Introduction Image maps allow you to designate...

Implementation of crawler Scrapy image created by dockerfile based on alpine

1. Download the alpine image [root@DockerBrian ~]...

JavaScript to achieve slow motion animation effect

This article shares the specific code for JavaScr...

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...

MySQL SQL statement performance tuning simple example

MySQL SQL statement performance tuning simple exa...

Website Color Schemes Choosing the Right Colors for Your Website

Does color influence website visitors? A few year...

Nodejs plug-in and usage summary

The operating environment of this tutorial: Windo...

How to use vs2019 for Linux remote development

Usually, there are two options when we develop Li...

How to create LVM for XFS file system in Ubuntu

Preface lvm (Logical Volume Manager) logical volu...

MySQL case when group by example

A mysql-like php switch case statement. select xx...

Basic usage of wget command under Linux

Table of contents Preface 1. Download a single fi...

ElementUI implements cascading selector

This article example shares the specific code of ...

js canvas to realize the Gobang game

This article shares the specific code of the canv...