当前位置:网站首页>[MySQL] query valid data based on time
[MySQL] query valid data based on time
2022-06-27 15:00:00 【Yiyuery】
Query the current time minute expireMin To expireMinEnd Internal data
The time parameter only needs to modify the divisor immediately 60 Represents one minute 60s
SELECT
dis.*
FROM
(SELECT
*,
(
UNIX_TIMESTAMP(gmt_deadline) - UNIX_TIMESTAMP(NOW())
) / 60 AS m
FROM
T_DISPATCH) dis
LEFT JOIN T_RECV_REPORT rec
on dis.src_id = rec.rep_id
WHERE dis.m <![CDATA[ >= ]]> #{expireMin}
AND dis.m <![CDATA[ <= ]]> #{expireMinEnd}
AND dis.disp_type=2
AND dis.disp_state=0
AND rec.rep_way=1
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
Query data older than seven days and set it to expired status
The time parameter only needs to modify the divisor immediately 3600*24 It means a day 24 Hours , Every hour 3600s
UPDATE
T_APOLLO_MSG_CACHE
SET
is_expired = 1
WHERE msg_id IN
(SELECT
msg.msg_id
FROM
(SELECT
*,
(
UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(gmt_update)
) / 3600 / 24 AS d
FROM
T_APOLLO_MSG_CACHE) msg
WHERE msg.is_send = 0
AND msg.recieve_user_token =#{token}
AND msg.d > #{validDay}) ;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
Query today's data
select COUNT(1)
from
T_DISPATCH
WHERE TO_DAYS(gmt_update) = TO_DAYS(NOW());
- 1.
- 2.
- 3.
- 4.
Actual case
resultMap
public class StatItem {
private String unit;
private Integer number;
public String getUnit() {
return unit;
}
public StatItem setUnit(String unit) {
this.unit = unit;
return this;
}
public Integer getNumber() {
return number;
}
public StatItem setNumber(Integer number) {
this.number = number;
return this;
}
}
<resultMap id="statItem" type="cn.showclear.utio.web.pojo.vo.StatItem">
<result column="unit" property="unit" jdbcType="VARCHAR"/>
<result column="number" property="number" jdbcType="INTEGER"/>
</resultMap>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
Query the hourly data of the current day
<!-- same day / Hours -->
<select id="statDispatchInDayWithDispType" resultMap="statItem">
SELECT
HOUR(dis.gmt_update) AS unit,
COUNT(1) AS number
FROM
T_DISPATCH dis
WHERE TO_DAYS(dis.gmt_update) = TO_DAYS(NOW())
AND dis.disp_type = #{dispType}
GROUP BY HOUR(dis.gmt_update)
ORDER BY HOUR(dis.gmt_update)
</select>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
Query daily data of the current month
<!-- The current month / Every day -->
<select id="statDispatchInMonthWithDispType" resultMap="statItem">
SELECT
COUNT(1) AS number,
DATE_FORMAT(dis.gmt_update, '%Y-%m-%d') AS unit
FROM
T_DISPATCH dis
WHERE DATE_FORMAT(dis.gmt_update, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
AND dis.disp_type = #{dispType}
GROUP BY DATE_FORMAT(dis.gmt_update, '%Y-%m-%d')
</select>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
Query the data of each month in the current year
<!-- The current year / monthly -->
<select id="statDispatchInYearWithDispType" resultMap="statItem">
SELECT
COUNT(1) AS number,
DATE_FORMAT(dis.gmt_update, '%Y-%m') AS unit
FROM
T_DISPATCH dis
WHERE DATE_FORMAT(dis.gmt_update, '%Y') = DATE_FORMAT(CURDATE(), '%Y')
AND dis.disp_type = #{dispType}
GROUP BY MONTH(dis.gmt_update)
</select>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
Reference resources :
1、mysql Query daily, weekly, monthly and yearly data methods
2、 mysql Query today 、 yesterday 、 Last month, 、 This month's data
3、mysql Query today 、 yesterday 、7 God 、 near 30 God 、 This month, 、 Last month data
边栏推荐
- PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)
- AbortController的使用
- What is the London Silver code
- Web chat room system based on SSM
- Abnormal analysis of pcf8591 voltage measurement data
- 反射学习总结
- 我想買固收+產品,但是不了解它主要投資哪些方面,有人知道嗎?
- 简析国内外电商的区别
- 优雅的自定义 ThreadPoolExecutor 线程池
- Design and implementation of reading app based on Web Platform
猜你喜欢

Atomic operation class

PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)

阅读别人的代码,是一种怎样的体验

How QT sets some areas to be transparent in the background image

CV领域一代宗师黄煦涛教授86岁冥诞,UIUC专设博士奖学金激励新锐

Design and implementation of food recipe and ingredients website based on vue+node+mysql

Acwing game 57
![[high concurrency] deeply analyze the callable interface](/img/24/33c3011752c8f04937ad68d85d4ece.jpg)
[high concurrency] deeply analyze the callable interface
![[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)](/img/29/73c381f14a09ecaf36a98d67d76720.png)
[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)

Integration of entry-level SSM framework based on XML configuration file
随机推荐
我想買固收+產品,但是不了解它主要投資哪些方面,有人知道嗎?
AQS抽象队列同步器
Daily 3 questions (1): find the nearest point with the same X or Y coordinate
请求一下子太多了,数据库危
Hyperledger Fabric 2. X custom smart contract
CAS之比较并交换
Multithreading Basics (III)
Resolve activity startup - lifecycle Perspective
AutoCAD - line width setting
注解学习总结
Cannot determine value type from string ‘<p>1</p>‘
[advanced MySQL] MTS master-slave synchronization principle and Practice Guide (7)
优雅的自定义 ThreadPoolExecutor 线程池
[WUSTCTF2020]girlfriend
What kind of experience is it to read other people's code
I want to buy fixed income + products, but I don't know what its main investment is. Does anyone know?
基于SSM的Web网页聊天室系统
反射学习总结
About sitemap XML problems
基于Vue+Node+MySQL的美食菜谱食材网站设计与实现