在PostgreSQL中查找重叠的日期范围 [英] Find overlapping date ranges in PostgreSQL
本文介绍了在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屋!
查看全文