这题是我上周的题目, 经过问老师之后, 发现我理解错了, 现在急需大家帮忙以下是英文原题Consider the following relational schema about daily stock prices.
StockPrice (stockid; timeid; price)

解决方案 »

  1.   

    看题目标题,我还以为是event问题的说
      

  2.   

    你的中文没有翻译准确。原文为:考虑如下关于股票日价的一个关系模式
    StockPrice (stockid; timeid; price)
    将日期 timeid 简化为整形,以表示第 X 天的股价
      

  3.   

    select a.stockid,a.timeid,avg(b.price)
    from StockPrice a ,StockPrice b
    where a.stockid=b.stockid
    and a.timeid>=b.timeid and a.timeid<=b.timeid+14
    group by a.stockid,a.timeidNote that we want strict 15-day moving average, meaning that
     There should be no 15-day moving average for the first 14 days (as shown in
    the above example).
     If there are missing data (e.g., the price for a stock at some date is missing)
    within the 15-day (sliding) window, the computation on this window should
    be abandoned.注意,这里是严格的15的平均价,即本日+前14天,如果缺少,则放弃。
      

  4.   

    select st.time_id,avg(stock.price) a from stock,stock st where stock.time_id<st.time_id 
    and st.time_id between st.time_id and st.time_id+5
    and st.time_id>=10  
    group by st.time_id;
      

  5.   

    mysql> select * from stock;
    +----+---------+-------+---------+
    | id | time_id | price | stockid |
    +----+---------+-------+---------+
    |  1 |       5 |    12 | 101     |
    |  2 |       6 |    10 | 101     |
    |  3 |       7 |     8 | 101     |
    |  4 |       8 |    13 | 101     |
    |  5 |       9 |    11 | 101     |
    |  6 |      10 |    11 | 101     |
    |  7 |      11 |    11 | 101     |
    |  8 |      12 |    16 | 101     |
    |  9 |      13 |    16 | 101     |
    | 10 |      14 |    15 | 101     |
    | 11 |      15 |    15 | 101     |
    | 12 |      16 |    14 | 101     |
    | 13 |      17 |    11 | 101     |
    | 14 |      18 |    10 | 101     |
    | 15 |      19 |    10 | 101     |
    | 16 |      20 |    10 | 101     |
    | 17 |      21 |    10 | 101     |
    | 18 |      22 |    12 | 101     |
    | 19 |      23 |  NULL | 101     |
    | 20 |      24 |    10 | 101     |
    +----+---------+-------+---------+
    20 rows in set (0.00 sec)
      

  6.   

    计算的是从第10天开始算起 每隔5天的平均价格 但是没有考虑到null的情形,应该如何操作?
      

  7.   


    这个query 是包含了缺少则放弃的 限制吗? 
    我看不懂这个是怎么判断缺少则放弃
      

  8.   

    没有包含
    select a.stockid,a.timeid,avg(b.price)
     from StockPrice a ,StockPrice b
     where a.stockid=b.stockid
     and a.timeid>=b.timeid and a.timeid  <=b.timeid+14
     group by a.stockid,a.timeid
     hvaing count(*)=15
      

  9.   


    哦 谢了  但是 能解析一下GROUP BY 那里 为什么要timeid呢
      

  10.   

    You are student of UNSW and study COMP9311, aren't you?