title: SQL Server : calculate percentage
body: <p>I need your help as my level in SQL is very weak, I'm trying to do something but can't find how to achieve it.</p>
  
  <p>Let's say I have the following rows</p>
  
  <pre><code>| Data| Status |   Date     |
  | A   |  OK    | 2017-01-20 |
  | B   |  KO    | 2017-01-20 |
  | C   |  OK    | 2017-01-20 |
  | A   |  OK    | 2017-01-21 |
  | B   |  KO    | 2017-01-21 |
  | C   |  KO    | 2017-01-21 |
  | A   |  OK    | 2017-01-22 |
  | B   |  KO    | 2017-01-22 |
  | C   |  OK    | 2017-01-22 |
  </code></pre>
  
  <p>I want to query the DB to get the percentage result of OK for 3 days so it's look like </p>
  
  <pre><code>A | 100%
  B | 0%
  C | 66%
  </code></pre>
  
  <p>I've done this for 1 Data but I'm stuck, maybe I need a loop or something else :</p>
  
  <pre><code>Select 
      Data, (Select Count(*) From DB Where 
      Date between '2017-01-20' and '2017-01-22' 
      And Status = 'OK') * 100 / (Select Count(*) From DB 
                                  Where Date between '2017-01-20' and '2017-01-22')
  
  From 
      DB
  </code></pre>