The difference between timestamp and sqltimestamp calculated by SQL.
SQL Calculation of timestamp difference
Overview
Sometimes we need to find some records by time, for example, calculate the record one hour before the sales time.
We can usually use the timestampdiff function of MYSQL to do this, but we cannot use the index. If the data volume is large, it will cause slow queries.
Use the code to calculate the time and then pass it to the SQL
We can use the JAVA code to calculate the time first and then pass it to the SQL statement to avoid using MYSQL functions.
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 first hour of the sales time. Then input the SQL statement and write it into the code slice statement. In this way, if the sales time field has an index, you can use the index.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!