In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces SQL how to calculate the difference of timestamp, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The method of calculating the difference of timestamp by SQL
Overview
Sometimes we need to find certain records according to time, such as calculating the records an hour before the time of sale.
Usually we can use the timestampdiff function of MYSQL to do this, but this can not use the index, if the amount of data is large, it will cause slow query.
Calculate the time with code and then transmit it to SQL
We can use JAVA code to calculate the time first, and then pass it to the SQL statement to avoid using the function of MYSQL.
Public long xxxx (long sellTimeFrom) {Calendar calendar = Calendar.getInstance (); calendar.setTime (new Date (sellTimeFrom)); calendar.set (Calendar.HOUR_OF_DAY,calendar.get (Calendar.HOUR_OF_DAY)-1); return calendar.getTime (). GetTime ();}
In this way, you can calculate the time an hour before the sales time. Then input the code chip `statement here in SQL, so that if the sales time field has an index, the index can be used.
Thank you for reading this article carefully. I hope the article "how to calculate the difference between SQL and timestamp" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.