MySQL Date function and bulk loop return primary Key ID

Source: Internet
Author: User

The actual project will always encounter a variety of time calculation queries and so many times is particularly troublesome before the company has a demand is roughly to query the current date and the database storage date difference, originally wrote a tool class call but finally think this is not good thinking can be solved with the function, did not expect to share the following, SQL is as follows:

Select DateDiff (' 2017-04-21 ', (select Now ()) as day, date subtraction gets the number of days, simple, get the current date is actually a function, but some MySQL version does not support the specific you try, There is also a date format query processing is also very simple date_format (
T1.cfcadownloadtime,
'%y-%m-%d%h:%i:%s ') write the format you want OK, the date this piece is relatively simple, but this loop batch return ID really is baffled me for a long time, we all know <selectkey resulttype= "Integer" Keyproperty = "UID" order= "after" >
SELECT
LAST_INSERT_ID () as UID
</selectKey> this way can return a single ID, in fact, his way is to query the last one to add data to the primary key, or usegeneratedkeys= "true" keyproperty= "rid" this way, but the bulk of him is not, Search in Baidu for a long time to see a lot of people also encountered this problem in fact the reason is also very simple MyBatis to 3.1 version above OK, this can be said to be mybatis a bug in 3.1 after the repair, although these problems seem simple but do it is really trouble, also is a lesson

MySQL Date function and bulk loop return primary Key ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.