1

次の表を参照する必要がstart_timeあります。ここで、フィールドend_timeは次のとおりです。TIME

 ____________________________________
| id | day | start_time |  end_time  |
|____|_____|____________|____________|
|  1 | 1   |    8:00    |    12:00   |

start_timeとの間の 60 分ごとの開始時刻を次のように取得したいと思いますend_time

 _______
| start |
|_______|
|  8:00 |
|  9:00 |
| 10:00 |
| 11:00 |

それは可能ですか?ありがとう

4

1 に答える 1

1

整数を持つテーブルがある場合、これは簡単です。フィールドが日時の場合、次のようにすることができます (最大 7 時間)。

select date_add(t.start_time, interval n.n hour)
from t join
     (select 0 as n union all select 1 union all select 2 union all select 3 union all
      select 4 union all select 5 union all select 6 union all select 7
     ) n
     on date_add(t.start_time, interval n.n hour) <= t.end_time

を使用timeすると、秒に変換してそこで算術演算を行うことで実行できます。

select sec_to_time((floor(time_to_sec(t.start_time - 1)/3600)+1) + n.n*3600)
from t join
     (select 0 as n union all select 1 union all select 2 union all select 3 union all
      select 4 union all select 5 union all select 6 union all select 7
     ) n
     on (floor(time_to_sec(t.start_time - 1)/3600)+1) + n.n*3600 <= t.end_time
于 2013-06-19T13:47:36.387 に答える