title: How to make the following SQL problem more optimise and in correct way
body: <p>The .CSV file supplied has 225146 records and has the following fields:</p>
  
  <pre><code>FLOW_ID – The unique identifier of the traffic flow measured;
  LINK_ID – The unique identifier of the road link being measured;
  LINK_DESC – A description of the road link being measured;
  FLOW_DIR – The direction of the traffic flow;
  PERIOD_TYPE – The type of period when traffic was measured;
  F00 to F33 – The traffic flow measured at each hour, i.e. 0:00, 1:00….23:00
  </code></pre>
  
  <p>this is the main table and split it to make it simple to use</p>
  
  <p><a href="https://i.stack.imgur.com/GNzmZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GNzmZ.png" alt="this is the main table and split it to make it simple to use"></a></p>
  
  <p>I Split into three tables</p>
  
  <ol>
  <li>Flow_Dim (flow_id(pk), Link_Desc, Flow_Dir) [with grouping]</li>
  <li>Period_Dim (p_id(pk), period_type) [just got three values with group by (grouping)]</li>
  <li><p>Traffic_Flow_Fact (flow_id(fk), p_id(fk), F00 to F23 then all the 24 columns of hours) [insert the  following query to make it simple]</p>
  
  <pre><code>INSERT INTO `Traffic_Flow_Fact` 
      (`flow_id`, `period_id`, `H0`, `H1`, `H2`, `H3`)
      SELECT junk.`FLOW_ID`, p.`p_id`, SUM(junk.`F00`), 
              SUM(junk.`F01`), SUM(junk.`F02`), 
              SUM(junk.`F03`)
  FROM TempJunk junk, Period_Dim p
  WHERE p.`PERIOD_TYPE` = junk.`PERIOD_TYPE`
  GROUP BY p.`PERIOD_TYPE`, junk.`FLOW_ID`, p.`p_id`
  </code></pre></li>
  </ol>
  
  <p>Following is the table Traffic_Flow_Fact</p>
  
  <p>I just want to know is there any other way to make hours and there traffic flow value in separate table so that I can find out following solutions - </p>
  
  <p>a) What are the top 5 busiest links during hours public holidays, school holidays and normal time (school term)? What is the average traffic on those links during those periods?</p>
  
  <p>b) What are the 3 least busy links during hours public holidays, school holidays and normal time (school term)?</p>
  
  <p>c) What are the peak time hours for Monash Freeway links? What about Princes Way links?</p>
  
  <p>I am not expecting any answers of these questions these just for reference so that you guys will what needs to be done</p>