当前位置:网站首页>[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
边栏推荐
- Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and the mobile phone can easily read literature
- Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
- Using redis skillfully to realize the like function, isn't it more fragrant than MySQL?
- 数学建模经验分享:国赛美赛对比/选题参考/常用技巧
- AQS Abstract queue synchronizer
- The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
- 基于 Nebula Graph 构建百亿关系知识图谱实践
- Abnormal analysis of pcf8591 voltage measurement data
- Pychart installation and setup
- LVI: feature extraction and sorting of lidar subsystem
猜你喜欢

Getting to know cloud native security for the first time: the best guarantee in the cloud Era

Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training

隱私計算FATE-離線預測

R language objects are stored in JSON

请求一下子太多了,数据库危

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

海量数据!秒级分析!Flink+Doris构建实时数仓方案
![[OS command injection] common OS command execution functions and OS command injection utilization examples and range experiments - based on DVWA range](/img/f2/458770fc74971bef23f96f87733ee5.png)
[OS command injection] common OS command execution functions and OS command injection utilization examples and range experiments - based on DVWA range

Make a ThreadLocal (source code) that everyone can understand

巧用redis实现点赞功能,它不比mysql香吗?
随机推荐
Volatile and JMM
PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)
Abnormal analysis of pcf8591 voltage measurement data
Is flutter easy to learn? How to learn? The most complete introduction and actual combat of flutter in history. Take it away without thanks~
基于Vue+Node+MySQL的美食菜谱食材网站设计与实现
简析国内外电商的区别
关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义
关于 Spartacus 的 sitemap.xml 问题
Notes learning summary
SQL parsing practice of Pisa proxy
HTTP Caching Protocol practice
AbortController的使用
Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance
Today, Teng Xu came out with 37k during the interview. It's really a miracle. He showed me his skill
Privacy computing fat offline prediction
PR second training notes
E-week finance Q1 mobile banking has 650million active users; Layout of financial subsidiaries in emerging fields
What is the London Silver unit
June 27, 2022 Daily: swin transformer, Vit authors and others said: a good basic model is the simple pursuit of CV researchers
Référence forte, faible, douce et virtuelle de threadlocal