我要做的是选择一个产品范围内有效的价格。
表:
create table #tblPreis
(
[Date] date,
[Layer] int,
[Site] int,
[item] int,
[price] money
)
insert into #tblPreis
values
('2015-08-19', 1, 1, 10, 0,90),
('2015-08-18', 1, 1, 10, 0,50),
('2015-08-17', 1, 1, 10, 0,50),
('2015-08-16', 1, 1, 10, 2,00),
('2015-08-15', 2, 1, 10, 2,00),
('2015-08-14', 1, 1, 10, 1,00),
('2015-08-19', 3, 1, 12, 3,00),
('2015-08-18', 1, 1, 9, 7,00),
('2015-08-17', 1, 1, 9, 8,00),
('2015-08-16', 1, 1, 9, 8,00),
('2015-08-15', 1, 1, 9, 8,00),
('2015-01-01', 1, 1, 9, 7,00);
我希望收到的是
DateStart DateEnd Item Price
2015-01-01 2015-08-14 9 7,00
2015-08-15 2015-08-17 9 8,00
2015-08-18 2015-08-18 9 7,00
2015-08-19 2015-08-19 12 3,00
2015-08-14 2015-08-14 10 1,00
2015-08-15 2015-08-16 10 2,00
2015-08-17 2015-08-18 10 0,50
2015-08-19 2015-08-19 10 0,90
正如您可以看到日期,项目和价格旁边的图层和其他列不感兴趣。
感谢您的任何建议。 低糜