AND & OR
ml.query does not use traditional logical operators like AND & OR but the same effect can be achieved by chaining multiple where methods together..where(columnName: string, operator: string, value: any).where(columnName: string, operator: string, value: any)
An or method can be chained between two where methods to filter data by a first condition OR a second condition.
.where(columnName: string, operator: string, value: any).or().where(columnName: string, operator: string, value: any)
var q = ml.query(); q.select('LowRate').from('hms/hotels'); q.where('LowRate','GreaterOR',100).where('LowRate','LessOR',500); q.run(function(data){ console.log(data); });
var q = ml.query(); q.select('LowRate').from('hms/hotels'); q.where('LowRate','LessOR',100).or().where('LowRate','GreaterOR',500); 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); 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>
<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','LessOR',10).or().where('LowRate','GreaterOR',500); 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>