Oracle最小最大日期列表之间的日期

时间:2016-05-04 12:09:59

标签: sql oracle

我在不同的日期有一张鱼的桌子。

桌面着陆:

Long ID, 
Long Vessel_id, -- vessel that is fishing 
TimeStamp fishing_date, 
double amount_cought
Long species_id;

接下来是一张使用这些船只捕鱼的公司表。

table ves_usage:

Long ID,
TimeStamp usage_start_date,
TimeStamp usage_end_date,
Long vessel_id,
Long using_company_id;

最后,我有一张许可证表,用于在特定年份捕捞特定物种。

表牌照:

Long ID,
int year, --the year that the lincence is active
Long licenced_company_id,--company who was given the licence
Long species_id; --species that the company can fish

我正在尝试从登陆表中选择具有指定物种,公司和船只的所有记录。我遇到的问题是我无法想出一种方法来选择ves_usage表记录的开始日期和结束日期之间的所有登陆记录。不确定我是否足够清楚:P 我想做一些像:

Select * 
from landings 
where fishing_date between <list of usage_start_date and usage_end_date from ves_usage table>

2 个答案:

答案 0 :(得分:0)

如果您希望查询基于ID中的ves_usage,则此查询将有效:

SELECT * 
FROM landings 
WHERE fishing_date BETWEEN
  (SELECT usage_start_date FROM ves_usage WHERE id = <id from ves_usage>)
  AND
  (SELECT usage_end_date FROM ves_usage WHERE id = <id from ves_usage>)

如果您想要不同的内容,请按照评论中的要求指定。

答案 1 :(得分:0)

如果我正确地关注你的表格,我相信查询会是这样的:

istringstream
相关问题