title: Conditional case in SQL query
body: <p>My table design is next</p>
  <pre><code>table oc_za_puni_uredjaj
  sif_company  (integer - primary, value for company)
  sif_device   (integer - primary, value for device)
  sif_nos      (integer - primary, value for customer)
  sif_mp       (integer - primary, value for customer's place)
  rbr          (integer - primary, value for customer's place item)
  ocitano      (integer - 0 - empty, 1 - full)
  datum        (date    - date of the record)
  area         (text    - name of area of customer)
  </code></pre>
  <p>Example of data in database is next</p>
  <pre><code>sif_company | sif_device | sifnos | sif_mp | rbr | ocitano | datum | area |
  ---------------------------------------------------------------------------
  1           |     1      | 1      | 1      | 1   | 1       |...    |abcd
  1           |     1      | 1      | 2      | 1   | 0       |...    |abcd
  1           |     1      | 2      | 1      | 1   | 1       |...    |abc
  1           |     1      | 1      | 2      | 1   | 1       |...    |abcd
  1           |     1      | 1      | 2      | 3   | 1       |...    |abcd
  </code></pre>
  <p>My existing query which works (for some cases) is next</p>
  <pre><code>SELECT area as naselje, 
      count(*) total, 
      sum(case when ocitano = 1 then 1 else 0 end) ocitano 
  FROM `oc_za_puni_uredjaj` 
  WHERE sif_company = 1 group by 1
  </code></pre>
  <p>The result looks like</p>
  <pre><code>naselje    |  total    |    ocitano
  ------------------------------------
  abc        |  1        |     1
  abcd       |  4        |     3
  </code></pre>
  <p>The problem is if i have same data for 2 different devices (<code>sif_device</code>). I could have data in table like below</p>
  <pre><code>sif_company | sif_device | sifnos | sif_mp | rbr | ocitano | datum | area |
  ---------------------------------------------------------------------------    
  1           |     2      | 1      | 1      | 1   | 0       |...    |abcd
  1           |     1      | 2      | 1      | 1   | 1       |...    |abcd
  1           |     2      | 2      | 1      | 1   | 1       |...    |abcd
  1           |     1      | 3      | 1      | 1   | 1       |...    |abc
  </code></pre>
  <p>My desired output for that data should look like</p>
  <pre><code>naselje    |  total    |    ocitano
  ------------------------------------
  abc        |  1        |     1
  abcd       |  2        |     2 
  </code></pre>
  <p>So if i have in table row with (<code>sif_nos</code>, <code>sif_mp</code>, <code>rbr</code>) for different device (<code>sif_device</code>) then i have cases:</p>
  <ul>
  <li>if only one of them has <code>ocitano = 1</code> then for that area i have to <strong>increment ocitano in output</strong> by 1 (there could be even one row just for one device)</li>
  <li>if there is several rows with <code>ocitano = 1</code> then i have to <strong>increment ocitano in output</strong> by 1</li>
  <li>if all of them got <code>ocitano = 0</code> then i <strong>don't increment ocitano in output</strong></li>
  </ul>
  <p><strong>EDIT</strong></p>
  <p><a href="http://sqlfiddle.com/#!9/a4b63" rel="nofollow noreferrer">SQL Fiddle</a></p>
  <p>Any help would be nice</p>
  <p><strong>EDIT 2</strong></p>
  <p>For example, if i have 3 devices, (1,2 and 3), there could be row with (<code>sif_nos</code>, <code>sif_mp</code>, <code>rbr</code>) for 1 device, for 2 device or for all (all 3 devices) and so on.</p>