Where Method
The where method is used to query data that matches specified conditions.Returns: ml.data.query.Query
.where(columnName: string, operator: string, value: any)
Optional Parameter for applying where filter before the groupby
.where(columnName: string, operator: string, value: any, whereFirst?: boolean)
| Parameter | Description |
|---|---|
| Column Name | Name of column |
| Operator | String value that represents one of the available operators (link to table below). |
| Value | Value data will be compared against |
| whereFirst | Optional Boolean for applying where filter before the groupby. |
var q = ml.query(); q.select('LowRate').from('hms/hotels'); q.where('LowRate','GreaterOR',100); q.run(function(data){ console.log(data); });
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { //create ml.query() var q = ml.query(); q.select('LowRate').from('hms/hotels'); q.where('LowRate','GreaterOR',450).where('LowRate','LessOR',500); //Take defaults to 100 if not included q.take(10); q.run(function(data){ console.log(data); //Show the data as an html table displayTable(document.getElementById("dataDiv"),data); }); }); function displayTable(dataDiv, data){ var rows = ml.data.query.Query.transposeQueryData(data.data); console.log(rows); var head = []; ml.each(rows[0], function(k,v) { head.push(k); }); rows.unshift(head); data=rows; var table = ml.$("<table/>").addClass('CSSTableGenerator'); ml.$.each(data, function(rowIndex, r) { var row = ml.$("<tr/>"); ml.$.each(r, function(colIndex, c) { var content = "<p>"+c+"</p>"; row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content)); }); table.append(row); }); ml.$(dataDiv).html(table); } </script> <style> table tr:nth-child(even) { background-color: #eee; } table tr:nth-child(odd) { background-color:#fff; } table th { background-color: black; color: white; padding: 4px; } table td { padding: 4px; } </style> </head> <body> <div id="dataDiv"></div> </body> </html>
Filter can be applied to columns of type (D = Double, I = Int32, S = String)
| Name | D | I | S | Description |
|---|---|---|---|---|
| Between | ● | ● | Column row values between a minimum and maximum, inclusive. | |
| Bottom | ● | ● | A given number of smallest column row values. | |
| Contains | ● | Column rows that contain a value, as a substring. [Not Case Sensitive], [commas are valid search terms] | ||
| ContainsAll | ● | Column rows that contain all of a list of values, as a substring. [Not Case Sensitive], [list is comma delimited and commas are NOT valid search terms] | ||
| ContainsAny | ● | Column rows that contain any of a list of values, as a substring. [Not Case Sensitive], [list is comma delimited and commas are NOT valid search terms] | ||
| ContainsNot | ● | Column rows that do not contain a single value as a sub string [Not Case Sensitive], [commas are valid search terms] | ||
| ContainsNone | ● | Column rows that do not contain any of a list of values, as a substring. [Not Case Sensitive], [list is comma delimited and commas are NOT valid search terms] | ||
| ContainsOr | ● | Column rows that contain any of a list of values, as a substring. Alias for “ContainsAny” [Not Case Sensitive], [list is comma delimited and commas are NOT valid search terms] | ||
| Equal | ● | ● | ● | Column rows that equal exactly some value. [Case Sensitive] |
| EqualAny | ● | ● | ● | Column rows that equal any of a list of values. [Case Sensitive] |
| EqualNone | ● | ● | Column rows that do not equal any of a list of values. [Case Sensitive] | |
| EqualNot | ● | ● | ● | Column rows that do not equal a value exactly. [Case Sensitive] |
| Greater | ● | ● | Column rows whose values are strictly greater than some value. | |
| GreaterOR | ● | ● | Column rows whose values are greater than or equal to some value. | |
| Less | ● | ● | Column rows whose values are strictly less than some value. | |
| LessOR | ● | ● | Column rows whose values are less than or equal to some value. | |
| NotBetween | ● | ● | Column row values not between a min and max, inclusive. | |
| Top | ● | ● | A given number of largest column row values. |
