In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to query the nearest recorded data in mysql, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Query scenario: the demand now is to query the users closest to the age of 20, and get the top 5
My current database record user age field record format is "1995-05-20", field name birthday
The solution is as follows:
1. First of all, when querying, it is converted to the user's age.
How to change the date format to age:
(1) the year in the current year-date format
Date_format (now (),'% Y')-from_unixtime (unix_timestamp (birthday),'% Y')
(2) the year in the current year-date format (different acquisition methods)
Date_format (now (),'% Y')-year (birthday)
two。 Get the closest data by sorting order by asb ()
Complete statement:
SELECT (date_format (now (),'% Y')-year (birthday)) as ageFROM userWHERE is_anchor = 1ORDER BY abs (20-age) limit 0Magne5 on how to query the closest record data in mysql is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.