title: YTD and MTD in the same query
body: <p>i have</p>
  
  <pre><code>create table 
      tbl(CustKey int, dt varchar(6), category varchar(20), amtbc int)
      insert into tbl values(2475,'201402','P',100) 
      insert into tbl values(2475,'201403','P',130) 
      insert into tbl values(2475,'201311','R',2056) 
      insert into tbl values(2475,'201312','R',978)
      insert into tbl values(2475,'201406','P',100) 
      insert into #tbl values(2475,'201406','R',410)   
      insert into tbl values(2475,'201401','P',200)     
      insert into #tbl values(2475,'201407','R',179)
      insert into tbl values(2475,'201404','P',100) 
      insert into #tbl values(2475,'201405','P',380) 
      insert into tbl values(2475,'201407','P',100)
      insert into #tbl values(2475,'201401','R',1377)
      insert into tbl values(9628,'201404','P',500) 
      insert into #tbl values(9628,'201405','P',500) 
      insert into tbl values(9628,'201402','P',500) 
      insert into #tbl values(9628,'201406','P',500)
      insert into tbl values(9628,'201401','P',500) 
      insert into #tbl values(9628,'201407','P',500) 
      insert into tbl values(9628,'201403','P',500)
  </code></pre>
  
  <blockquote>
    <p>select * from tbl:</p>
  </blockquote>
  
  <pre><code>CustKey dt  category    amtbc
  2475  201402    P        100
  2475  201403    P        130
  2475  201311    R        2056
  2475  201312    R        978
  2475  201406    P        100
  2475  201406    R        410
  2475  201401    P        200
  2475  201407    R        179
  2475  201404    P        100
  2475  201405    P        380
  2475  201407    P        100
  2475  201401    R        1377
  9628  201404    P        500
  9628  201405    P        500
  9628  201402    P        500
  9628  201406    P        500
  9628  201401    P        500
  9628  201407    P        500
  9628  201403    P        500
  </code></pre>
  
  <p>Then i have this select, which count SUM amtbc per custkey. per category, per dt(monthly)</p>
  
  <blockquote>
    <p>select  custkey, dt, sum (case when category in ('R') then amtbc else
    0 end) as ostatnisuma,</p>
    
    <p>sum (case when category in ('P') then amtbc else 0 end) as
    residencesuma from tbl group by custkey,dt order by CustKey,dt<br>
    which gives me this: </p>
  </blockquote>
  
  <pre><code>custkey dt  ostatnisuma residencesuma
  2475    201311  2056         0
  2475    201312  978          0
  2475    201401  1377        200
  2475    201402  0           100
  2475    201403  0           130
  2475    201404  0           100
  2475    201405  0           380
  2475    201406  410         100
  2475    201407  179         100
  9628    201401  0           500
  9628    201402  0           500
  9628    201403  0           500
  9628    201404  0           500
  9628    201405  0           500
  9628    201406  0           500
  9628    201407  0           500
  </code></pre>
  
  <p>So now i know the amounts for each month. But id like to know for category P amount for every month(its ok) but for category R i want to know the amount in whole year, and enter this amount for whole year into every row for that year. so the final table will look like:</p>
  
  <pre><code>custkey dt  ostatnisuma residencesuma
  2475  201311    2056       0
  2475  201312    978        0
  2475  201401    1377    1110
  2475  201402    0       1110
  2475  201403    0       1110
  2475  201404    0       1110
  2475  201405    0       1110
  2475  201406    410     1110
  2475  201407    179     1110
  9628  201401    0       3500
  9628  201402    0       3500
  9628  201403    0       3500
  9628  201404    0       3500
  9628  201405    0       3500
  9628  201406    0       3500
  9628  201407    0       3500
  </code></pre>
  
  <p>Note that in reality, the number of categories is like 100+ and about 500 000 values... Thank you very much in advance for you help</p>