How can I write SQL statements based on the latest three-day record in the mysql table?

Source: Internet
Author: User
Mysql records the latest three days in the table, how to write SQL statements to mysql records the latest three days in the table, and how to write SQL statements. I checked one from the Internet, but this is based on the current time as the starting point to take the records of the last few days select & nbsp; * & nbsp; from & nbsp; rewards & nbsp; where & n mysql takes the three-day record of "latest" in the table, and how to write SQL statements
Mysql fetch table LatestHow to write SQL statements for a three-day record. I checked one from the Internet, but this is Start from the current time to get the last few daysSelect * from rewards where DATE_SUB (CURDATE (), INTERVAL 4 DAY)
<= Date (day) order by day desc MySQL shared:
------ Solution --------------------
Try
Select * from tt inner join
(Select date (day) as 'day' from tt group by date ('day') order by 'day' desc limit 3)
On date (tt. day) = a. day

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.