title: CouchDB - Map Reduce similar to SQL Group by
body: <p>Consider following sample documents stored in CouchDB</p>
  
  <pre><code> {
  "_id":....,
  "rev":....,
  "type":"orders",
  "Period":"2013-01",
  "Region":"East",
  "Category":"Stationary",
  "Product":"Pen",
  "Rate":1,
  "Qty":10,
  "Amount":10
  }
  
  {
  "_id":....,
  "rev":....,
  "type":"orders",
  "Period":"2013-02",
  "Region":"South",
  "Category":"Food",
  "Product":"Biscuit",
  "Rate":7,
  "Qty":5,
  "Amount":35
  }
  </code></pre>
  
  <p>Consider following SQL query</p>
  
  <pre><code>SELECT Period, Region,Category, Product, Min(Rate),Max(Rate),Count(Rate), Sum(Qty),Sum(Amount)
  FROM Sales
  GROUP BY Period,Region,Category, Product;
  </code></pre>
  
  <p>Is it possible to create map/reduce views in couchdb equivalent to the above SQL query and to produce output like</p>
  
  <pre><code>[
      {
          "Period":"2013-01",
          "Region":"East",
          "Category":"Stationary",
          "Product":"Pen",
          "MinRate":1,
          "MaxRate":2,
          "OrdersCount":20,
          "TotQty":1000,
          "Amount":1750
      },
      {
      ... 
      }
  
  ]
  </code></pre>