如果我无法解释这个问题,请原谅我。但基本上我有:
|Place| Agreement | Open Date | Closed Date | FlagDate | 1 | a | 1/29/2011 | 7/29/2011 | 2/29/2011 | 1 | b | 2/15/2016 | 7/30/2016 | 2/29/2011 | 1 | c | 3/29/2015 | 8/02/2015 | 2/29/2011 | 2 | d | 4/29/2011 | 7/28/2011 | 6/29/2012 | 2 | e | 5/29/2012 | 7/30/2012 | 6/29/2012 | 3 | f | 6/29/2011 | 8/01/2011 | 7/15/2011 | 3 | g | 7/29/2012 | 8/02/2012 | 7/15/2011
单个地方可以有多个协议。 FlagDate对于每个地方都是相同的(即所有地方1的FlagDate都是2011年2月29日)
我想做的只是选择FlagDate落在开盘和收盘日期之间的协议(开盘和收盘日期永远不会与不同的协议重叠。)所以上面的输出将是
|Place| Agreement | Open Date | Closed Date | FlagDate | 1 | a | 1/29/2011 | 7/29/2011 | 2/29/2011 | 2 | e | 5/29/2012 | 7/30/2012 | 6/29/2012 | 3 | f | 6/29/2011 | 8/01/2011 | 7/15/2011
答案 0 :(得分:2)
您可以在WHERE子句中使用BETWEEN运算符来执行此操作:
SELECT * FROM yourtable WHERE flagdate BETWEEN opendate AND closeddate;