美文网首页SQL练习
SQL两个日期相减

SQL两个日期相减

作者: 你说我对钱一往情深 | 来源:发表于2018-10-26 11:48 被阅读0次
#年、月、天、时、分、秒
datediff(yy,date1,date2)     
datediff(m,date1,date2)      
datediff(d,date1,date2)
datediff(hh,date1,date2)
datediff(n,date1,date2)
datediff(s,date1,date2)
datediff(ms,date1,date2)

例子:

select product_id,DATEDIFF(MINUTE,min(client_time),max(client_time)) as time
from game_publish
where product_id = 1000272
and client_time>='2018-10-19 00:00:00'
and client_time<'2018-10-20 00:00:00'
group by product_id,token
order by product_id;
product_id time
1000272 54
1000272 61

相关文章

网友评论

    本文标题:SQL两个日期相减

    本文链接:https://www.haomeiwen.com/subject/beektqtx.html