根据条件

时间:2015-12-18 18:40:57

标签: mysql sql database insert sql-insert

大家好,

我在MySQL数据库中有以下表格。

   id   report_date value    event_id   event_start_date    event_end_date
    1   5/31/1978   10          
    1   6/30/1978   20          
    1   7/31/1978   30          
    1   8/31/1978   40          
    1   9/30/1978   70          
    1   10/31/1978  90          
    1   11/30/1978  10         a           11/25/1978              11/29/1978
    1   12/31/1978  30          
    1   1/31/1979   50          
    2   7/31/2012   28          
    2   8/31/2012   40          
    2   9/30/2012   60          
    2   10/31/2012  100        b            10/2/2012              10/4/2012
    2   11/30/2012  120         
    2   12/31/2012  130         
    2   1/31/2013   140     

我想在事件开始日期和事件结束日期之间为该ID添加行,其值为零,这些日期将作为报告日期。所以结果表应该是这样的:

id  report_date value   event_id    event_start_date    event_end_date
1   5/31/1978   10          
1   6/30/1978   20          
1   7/31/1978   30          
1   8/31/1978   40          
1   9/30/1978   70          
1   10/31/1978  90          
1   11/30/1978  10          a        11/25/1978           11/29/1978
1   11/25/1978  0           a        11/25/1978           11/29/1978
1   11/26/1978  0           a        11/25/1978           11/29/1978
1   11/27/1978  0           a        11/25/1978           11/29/1978
1   11/28/1978  0           a        11/25/1978           11/29/1978
1   11/29/1978  0           a        11/25/1978           11/29/1978
1   12/31/1978  30          
1   1/31/1979   50          
2   7/31/2012   28          
2   8/31/2012   40          
2   9/30/2012   60          
2   10/31/2012  100          b        10/2/2012           10/4/2012
2   10/2/2012   0            b        10/2/2012           10/4/2012
2   10/3/2012   0            b        10/2/2012           10/4/2012
2   10/4/2012   0            b        10/2/2012           10/4/2012
2   11/30/2012  120         
2   12/31/2012  130         
2   1/31/2013   140 

我无法找到办法。有人请帮我解决这个问题。 感谢

0 个答案:

没有答案