SQL Puzzle:只有每日价格表中的月度价格

时间:2018-01-16 22:54:01

标签: sql matlab

是否可以获得一个月的第一个值?

     Isin            Date          Price 
'AT0000652011'  '01-Jan-2004'   22,7700000000000
'AT0000652011'  '02-Jan-2004'   23,0300000000000
'AT0000652011'  '05-Jan-2004'   23,7000000000000
'AT0000652011'  '06-Jan-2004'   23,7000000000000
...
'AT0000652011'  '29-Jan-2004'   24,3800000000000
'AT0000652011'  '30-Jan-2004'   24,1900000000000
'AT0000652011'  '02-Feb-2004'   24,4500000000000
'AT0000652011'  '03-Feb-2004'   24,2900000000000

在这里你看到有时一个月的第一个月是在周末,因此没有任何价格?

此表由Matlab创建

Select List.* From List where List.Date between #01/01/2004# and #01/01/2005#

1 个答案:

答案 0 :(得分:0)

这是一种方法:

Select l.*
From l 
where l.date = (select min(l2.date)
                from list l2
                where l2.isin = l.isin and
                      year(l2.date) = year(l.date) and
                      month(l2.date) = month(l.date)
               );