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. Syntax Multiple where methods can be chained together to filter data by a first condition AND a second condition. .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) AND Example
  1. var q = ml.query();
  2. q.select('LowRate').from('hms/hotels');
  3. q.where('LowRate','GreaterOR',100).where('LowRate','LessOR',500);
  4. q.run(function(data){
  5. console.log(data);
  6. });
OR Example
  1. var q = ml.query();
  2. q.select('LowRate').from('hms/hotels');
  3. q.where('LowRate','LessOR',100).or().where('LowRate','GreaterOR',500);
  4. q.run(function(data){
  5. console.log(data);
  6. });
AND Demo
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. //create ml.query()
  8. var q = ml.query();
  9. q.select('LowRate').from('hms/hotels');
  10. q.where('LowRate','GreaterOR',450).where('LowRate','LessOR',500);
  11. q.run(function(data){
  12. console.log(data);
  13. //Show the data as an html table
  14. displayTable(document.getElementById("dataDiv"),data);
  15. });
  16.  
  17. });
  18.  
  19. function displayTable(dataDiv, data){
  20. var rows = ml.data.query.Query.transposeQueryData(data.data);
  21. console.log(rows);
  22. var head = [];
  23. ml.each(rows[0], function(k,v) {
  24. head.push(k);
  25. });
  26. rows.unshift(head);
  27. data=rows;
  28. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  29. ml.$.each(data, function(rowIndex, r) {
  30. var row = ml.$("<tr/>");
  31. ml.$.each(r, function(colIndex, c) {
  32. var content = "<p>"+c+"</p>";
  33. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  34. });
  35. table.append(row);
  36. });
  37.  
  38. ml.$(dataDiv).html(table);
  39. }
  40. </script>
  41. <style>
  42. table tr:nth-child(even) {
  43. background-color: #eee;
  44. }
  45. table tr:nth-child(odd) {
  46. background-color:#fff;
  47. }
  48. table th {
  49. background-color: black;
  50. color: white;
  51. padding: 4px;
  52. }
  53. table td {
  54. padding: 4px;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div id="dataDiv"></div>
  60. </body>
  61. </html>
OR Demo
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. //create ml.query()
  8. var q = ml.query();
  9. q.select('LowRate').from('hms/hotels');
  10. q.where('LowRate','LessOR',10).or().where('LowRate','GreaterOR',500);
  11. q.run(function(data){
  12. console.log(data);
  13. //Show the data as an html table
  14. displayTable(document.getElementById("dataDiv"),data);
  15. });
  16.  
  17. });
  18.  
  19. function displayTable(dataDiv, data){
  20. var rows = ml.data.query.Query.transposeQueryData(data.data);
  21. console.log(rows);
  22. var head = [];
  23. ml.each(rows[0], function(k,v) {
  24. head.push(k);
  25. });
  26. rows.unshift(head);
  27. data=rows;
  28. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  29. ml.$.each(data, function(rowIndex, r) {
  30. var row = ml.$("<tr/>");
  31. ml.$.each(r, function(colIndex, c) {
  32. var content = "<p>"+c+"</p>";
  33. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  34. });
  35. table.append(row);
  36. });
  37.  
  38. ml.$(dataDiv).html(table);
  39. }
  40. </script>
  41. <style>
  42. table tr:nth-child(even) {
  43. background-color: #eee;
  44. }
  45. table tr:nth-child(odd) {
  46. background-color:#fff;
  47. }
  48. table th {
  49. background-color: black;
  50. color: white;
  51. padding: 4px;
  52. }
  53. table td {
  54. padding: 4px;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div id="dataDiv"></div>
  60. </body>
  61. </html>