JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://alasql.org/console/alasql.min.js"></script>
<h3>AlaSQL and Common table Expressions</h3>
<p>In AlaSQL you can use WITH caluse with SELECT operator to create temporary tables for current select (a.k.a. Commom Table Expressions).</p>
<div id="res"></div>
JavaScript
alasql(function(){/*
CREATE TABLE grocery (name STRING, price MONEY, quantity INT);
INSERT INTO grocery VALUES ("Apples",10,10),("Melons",15,20),("Cucumbers",40,50);
*/});
var res = alasql(function(){/*
With Totals as
(
select *,
price * quantity as [Total price]
from grocery
)
select *
, case
when [Total price]>100 and [Total price]<= 200 then '2%'
when [Total price]>200 and [Total price]<= 300 then '3%'
when [Total price]>300 and [Total price]<= 400 then '4%'
else '0%'
end as tax
from
Totals
*/});
document.getElementById("res").textContent = JSON.stringify(res);