2022-09-14 20:27:53 +00:00
-- datatable(Supplier:string, Fruit:string, Price: real, Purchase:datetime)
-- [
-- 'Aldi','Apple',4,'2016-09-10',
-- 'Costco','Apple',2,'2016-09-11',
-- 'Aldi','Apple',6,'2016-09-10',
-- 'Costco','Snargaluff',100,'2016-09-12',
-- 'Aldi','Apple',7,'2016-09-12',
-- 'Aldi','Snargaluff',400,'2016-09-11',
-- 'Costco','Snargaluff',104,'2016-09-12',
-- 'Aldi','Apple',5,'2016-09-12',
-- 'Aldi','Snargaluff',600,'2016-09-11',
-- 'Costco','Snargaluff',200,'2016-09-10',
-- ]
DROP TABLE IF EXISTS Ledger ;
CREATE TABLE Ledger
(
Supplier Null able ( String ) ,
Fruit String ,
Price Float64 ,
Purchase Date
) ENGINE = Memory ;
INSERT INTO Ledger VALUES ( ' Aldi ' , ' Apple ' , 4 , ' 2016-09-10 ' ) , ( ' Costco ' , ' Apple ' , 2 , ' 2016-09-11 ' ) , ( ' Aldi ' , ' Apple ' , 6 , ' 2016-09-10 ' ) , ( ' Costco ' , ' Snargaluff ' , 100 , ' 2016-09-12 ' ) , ( ' Aldi ' , ' Apple ' , 7 , ' 2016-09-12 ' ) , ( ' Aldi ' , ' Snargaluff ' , 400 , ' 2016-09-11 ' ) , ( ' Costco ' , ' Snargaluff ' , 104 , ' 2016-09-12 ' ) , ( ' Aldi ' , ' Apple ' , 5 , ' 2016-09-12 ' ) , ( ' Aldi ' , ' Snargaluff ' , 600 , ' 2016-09-11 ' ) , ( ' Costco ' , ' Snargaluff ' , 200 , ' 2016-09-10 ' ) ;
set dialect = ' kusto ' ;
print ' -- extend #1 -- ' ;
Ledger | extend PriceInCents = 100 * Price | take 2 ;
print ' -- extend #2 -- ' ;
Ledger | extend PriceInCents = 100 * Price | sort by PriceInCents asc | project Fruit , PriceInCents | take 2 ;
print ' -- extend #3 -- ' ;
Ledger | extend PriceInCents = 100 * Price | sort by PriceInCents asc | project Fruit , PriceInCents | summarize AveragePrice = avg ( PriceInCents ) , Purchases = count ( ) by Fruit | extend Sentence = strcat ( Fruit , ' cost ' , tostring ( AveragePrice ) , ' on average based on ' , tostring ( Purchases ) , ' samples. ' ) | project Sentence ;
print ' -- extend #4 -- ' ;
Ledger | extend a = Price | extend b = a | extend c = a , d = b + 500 | extend Pass = bool ( b = = a and c = = a and d = = b + 500 ) | summarize binary_all_and ( Pass ) ;
print ' -- extend #5 -- ' ;
Ledger | take 2 | extend strcat ( Fruit , ' was purchased from ' , Supplier , ' for $ ' , tostring ( Price ) , ' on ' , tostring ( Purchase ) ) | extend PriceInCents = 100 * Price ;
print ' -- extend #6 -- ' ;
2022-10-06 20:24:48 +00:00
Ledger | extend Price = 100 * Price ;
2022-09-14 20:27:53 +00:00
print ' -- extend #7 -- ' ;
2022-10-06 20:24:48 +00:00
print a = 4 | extend a = 5 ;
2022-09-14 20:27:53 +00:00
print ' -- extend #8 -- ' ;
-- print x = 5 | extend array_sort_desc(range(0, x), range(1, x + 1))
2022-09-28 14:30:20 +00:00
print ' -- extend #9 -- ' ;
print x = 19 | extend = 4 + ; -- { clientError SYNTAX_ERROR }
print ' -- extend #10 -- ' ;
Ledger | extend PriceInCents = * Price | sort by PriceInCents asc | project Fruit , PriceInCents | summarize AveragePrice = avg ( PriceInCents ) , Purchases = count ( ) by Fruit | extend Sentence = strcat ( Fruit , ' cost ' , tostring ( AveragePrice ) , ' on average based on ' , tostring ( Purchases ) , ' samples. ' ) | project Sentence ; -- { clientError SYNTAX_ERROR }
2023-04-03 01:14:09 +00:00
print ' -- extend #11 -- ' ; -- should ideally return this in the future: 5 [2,1] because of the alias ex
2022-09-28 14:30:20 +00:00
print x = 5 | extend ex = array_sort_desc ( dynamic ( [ 1 , 2 ] ) , dynamic ( [ 3 , 4 ] ) ) ;