想象一下下表:
ID Name Type Start_Date End_Date
1 Cust_1 Retail 01/01/2010 21/07/2010
1 Cust_1 Oher 22/07/2010 17/05/2012
1 Cust_1 Corp 18/05/2012 31/12/9999
根据作为参数发送的日期,我想知道是否有任何方法可以构建返回正确类型的视图。例如:
SELECT Type WHERE date_to_analyse = '21/06/2010'
应该返回 'Retail'
SELECT Type WHERE date_to_analyse = '18/06/2012
' 应该返回 'Corp'
Date_to_analysis 不是表的列,我想避免使用存储过程。
我的想法是使查询“干净”,而不是使用以下查询
SELECT Type WHERE date_to_analyse >= Start_Date AND date_to_analyse < End_Date
这甚至可能吗?
谢谢