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

How to count MySQL query time

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly tells you briefly how to count MySQL query time. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on how to count MySQL query time can bring you some practical help.

Now suppose you have an order data sheet:

CREATE TABLE `order` (`id` int (11) unsigned NOT NULL AUTO_INCREMENT, `order_ sn` varchar (50) CHARACTER SET utf8 NOT NULL DEFAULT''COMMENT' order number Guarantee unique', 'create_ at` int (11) NOT NULL DEFAULT' 0' COMMENT 'creation time', 'success_ at` int (11) NOT NULL DEFAULT' 0' COMMENT 'order fulfillment time', 'creator_ id` varchar (50) CHARACTER SET utf8 NOT NULL DEFAULT' 'COMMENT' order creator', PRIMARY KEY (`id`), UNIQUE KEY `order Sn` (`order_ Sn`),) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT=' order Table'

Now take the table above as an example to query the relevant data:

Query all completed order numbers today:

SELECT `order_ sn` FROM `order` WHERE YEARWEEK (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = date_format (now (),'% Ymuri% mmi% d')

Query all completed order numbers for the current week:

SELECT `order_ sn` FROM `order` WHERE YEARWEEK (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = YEARWEEK (now ())

Query all completed order numbers last week:

SELECT `order_ sn` FROM `order` WHERE YEARWEEK (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = YEARWEEK (now ())-1

Query all completed order numbers for the current month:

Select `order_ sn` from `order` where FROM_UNIXTIME (success_at,'%Y-%m') = date_format (now (),'% Ymuri% m')

Query all completed order numbers in the last month:

Select `order_ sn` from `order` where FROM_UNIXTIME (success_at,'%Y-%m') = date_format (DATE_SUB (curdate (), INTERVAL 1 month),'% Ymuri% m')

Query the order number that has been completed 6 months from now:

Select `order_ sn` from `order` where FROM_UNIXTIME (success_at,'%Y-%m-%d% H15% iGV% s') between date_sub (now (), interval 6 month) and now ()

Query all completed order numbers for the quarter:

Select `order_ sn` from `order` where QUARTER (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = QUARTER (now ())

Query all completed order numbers for the previous quarter:

Select `order_ sn`from `order` where QUARTER (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = QUARTER (DATE_SUB (now (), interval 1 QUARTER))

To enquire about the order numbers of all completed orders this year:

Select `order_ sn` from `order` where YEAR (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = YEAR (NOW ())

Query the order numbers of all completed orders in the previous year:

Select `order_ sn`from `order` where year (FROM_UNIXTIME (success_at,'%Y-%m-%d')) = year (date_sub (now (), interval 1 year))

How to count the MySQL query time will first tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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