在 PostgreSQL 中查找重叠的日期范围 [英] Find overlapping date ranges in PostgreSQL

查看:32
本文介绍了在 PostgreSQL 中查找重叠的日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是正确的吗?

SELECT * 
FROM   contract 
JOIN   team USING (name_team) 
JOIN   player USING(name_player) 
WHERE  name_team = ? 
AND    DATE_PART('YEAR',date_join)>= ? 
AND    DATE_PART('YEAR',date_leave)<= ?

我的表 contract 包含球员姓名、球队名称以及他加入和离开俱乐部的日期.
我想制作一个功能,列出特定年份球队中的所有球员.
上面的查询似乎不起作用......

My table contract has the player name, team name and the dates when he joined and left the club.
I want to make a function listing all players that were on the team in specific years.
The above query doesn't seem to be working ...

推荐答案

为什么不使用无日期部分的东西:

Why not use between without the date part thing:

WHERE datefield BETWEEN '2009-10-10 00:00:00' AND '2009-10-11 00:00:00'

或者类似的东西?

这篇关于在 PostgreSQL 中查找重叠的日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆