In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to query the data of the day before the current time interval in MySQL". In the daily operation, I believe many people have doubts about how to query the data of the day before the current time interval in MySQL. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to query the data of the day before the current time interval in MySQL". Next, please follow the editor to study!
1. Background
In the actual project, we will encounter the situation of distributed timing task execution. Sometimes when the timing task is executed, if the amount of data queried is relatively large, we will choose to execute the data filtered several days ago.
Avoid problems such as OOM caused by excessive memory consumption or long execution time caused by executing a full amount of data.
Here we will use SQL to filter queries with the current interval of one or more days.
1.1. Query SQL statement
Here, a talk_course table is used as the execution form for querying the sql statement. The fields of the table are as follows:
There are roughly the following test data in the table:
The SQL statement of the day before the current execution time is as follows:
# query the data 1 day before the current time SELECT * FROM `talk_ room` tWHERE t.createTime = date_sub (now (), interval 1 day)
Query results:
Query the time of the day before the current time:
# query the day before the current time SELECT date_sub (now (), interval 1 day) as yesterday1.2. Query sentence analysis
Two functions are used here:
DATE_ADD (date,INTERVAL expr unit)
DATE_SUB (date,INTERVAL expr unit)
The DATE_ADD () function adds the specified time interval to the date.
The DATE_SUB () function reduces the specified time interval to the date.
Where the expr parameter is the interval you want to add.
The type parameter can be the following values:
Type value MICROSECONDSECONDMINUTEHOURDAYWEEKMONTHQUARTERYEARSECOND_MICROSECONDMINUTE_MICROSECONDMINUTE_SECONDHOUR_MICROSECONDHOUR_SECONDHOUR_MINUTEDAY_MICROSECONDDAY_SECONDDAY_MINUTEDAY_HOURYEAR_MONTH so far, the study on "how to query the data of one day before the current time interval in MySQL" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.