.groupyby (columnName.value)

groupby value will split the data into bins based on the min and max of the column data. For example, if column data ranged from 1 to 20 and the query requests 4 bins, the bin ranges would be 1-5, 6-10, 11-15, 16-20. This is useful when creating histograms.

Aggregate functions can then be used to calculate interesting data about each bin. For example, how many records are in the 1-5 bin, or what is the max record in the 16-20 bin.

When a bin does not include any records, that bin is not returned from the query. For example, if a query requests 4 bins, but only 3 of those bins contain data, the data response will only have a length of 3. To match bins with the response data, the ".key" aggregate must be used.

When keys are missing it means there was no data in groups 4-8 to return. Groupby value takes the full range min and max and tries to split them evenly according to value.10 or value.100.

Syntax .groupby(columnName.value.count: string) Example
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors');
  8. q.select('Amount.count','Amount.min','Amount.max', 'Amount.key');
  9. q.groupby('Amount.value.10');
  10. q.orderby('Amount');
  11.  
  12. q.run(function (data, query) {
  13. var dataDiv = document.getElementById("dataDiv");
  14. dataDiv.innerHTML = ml.util.JsonHighlight(data);
  15. });
  16.  
  17. });
  18. </script>
  19. </head>
  20. <body>
  21. <div id="dataDiv">
  22. </div>
  23. </body>
  24. </html>
Special groupbys