【问题标题】:SQL Puzzle: Only monthly prices from a daily-prices tableSQL 谜题:只有每日价格表中的每月价格
【发布时间】:2018-01-17 20:54:51
【问题描述】:

是否有可能只获得一个月的第一个值?

     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#

【问题讨论】:

    标签: sql matlab


    【解决方案1】:

    这是一种方法:

    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)
                   );
    

    【讨论】:

    • 1. “... from list l2 where l2.isin...” 我需要删除“list”,对吗?或者这是一个功能?如果它是一个函数,它就不起作用:-D --- 2. Matlab 现在运行了 15 分钟,尽管我将查询减少了 " ... where l2.isin = l.isin and year(l2.date) = year(l.date) and month(l2.date) = month(l.date) and l2.date
    猜你喜欢
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多