Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Optimization skills of Mysql querying dates according to time

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

For example, the query of newly registered users yesterday can be written in the following two ways:

EXPLAINselect * from chess_user u where DATE_FORMAT (u.registerless timekeeping% YMY% mMUE% d') = '2018-01-25 from chess_user u where u.register_time BETWEEN' 2018-01-25 0000VV 00' and '2018-01-25 23V 59from chess_user 59'

The register_time field is of type datetime. If it is converted to date matching, all rows need to be queried and filtered. And the second way of writing, you can use to build an index on the register_time field, the query is very fast!

Attached date conversion function

DECLARE yt varchar (10); # yesterday's DECLARE yt_bt varchar (19); # yesterday's start time DECLARE yt_et varchar (19); # yesterday's end time # set the variable SET yt=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Ymuri% mmi% d'); SET yt_bt=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Y-%m-%d 00lv 0000') SET yt_et=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Y-%m-%d 23 now 59')

Summary

The above is the editor to introduce to you the Mysql query date according to time optimization skills, I hope to help you, if you have any questions, please leave me a message, the editor will reply to you in time. Thank you very much for your support to the website!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report