.groupby(columnName.FirstLetter)
groupby FirstLetter provides the ability to group string columns by the first letter. Syntax .groupby(columnName.FirstLetter: string) and .groupby(columnName.FirstLetterNoCase: string) columnName.key

If columnName.key is in the select statement, the result data will contain an array of first letters.

Example
  1. var q = ml.query().from('Example/PopularGirlNames1');
  2. q.select('Name.key', 'Name.count');
  3. q.groupby('Name.FirstLetter').orderby('Name.count.desc');
  4. q.run(function(data){
  5. console.log(data);
  6. });
Demo
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6. var q = ml.query().from('Example/PopularGirlNames1');
  7.  
  8. // choose the columns to return
  9. q.select('Name.key', 'Name.count');
  10.  
  11. // group the data
  12. q.groupby('Name.FirstLetter').orderby('Name.count.desc');
  13.  
  14. // execute the query and process the return with the callback
  15. q.run(function(data){
  16. console.log(data);
  17.  
  18. //Show the data as an html table
  19. displayTable(document.getElementById("dataDiv"),data);
  20. });
  21.  
  22. });
  23.  
  24. function displayTable(dataDiv, data){
  25. var rows = ml.data.query.Query.transposeQueryData(data.data);
  26. console.log(rows);
  27. var head = [];
  28. ml.each(rows[0], function(k,v) {
  29. head.push(k);
  30. });
  31. rows.unshift(head);
  32. data=rows;
  33. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  34. ml.$.each(data, function(rowIndex, r) {
  35. var row = ml.$("<tr/>");
  36. ml.$.each(r, function(colIndex, c) {
  37. var content = "<p>"+c+"</p>";
  38. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  39. });
  40. table.append(row);
  41. });
  42.  
  43. ml.$(dataDiv).html(table);
  44. }
  45. </script>
  46. <style>
  47. table tr:nth-child(even) {
  48. background-color: rgb(231, 231, 231)
  49. }
  50. table tr:nth-child(odd) {
  51. background-color:#fff;
  52. }
  53. table th {
  54. background-color: rgb(86, 110, 140);
  55. color: white;
  56. padding: 5px;
  57. }
  58. table td {
  59. padding: 5px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div id="dataDiv"></div>
  65. </body>
  66. </html>
Special groupbys