Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active May 15, 2022 07:47
Show Gist options
  • Save nordineb/91e7da4320c27cb71a31b849c5197ba0 to your computer and use it in GitHub Desktop.
Save nordineb/91e7da4320c27cb71a31b849c5197ba0 to your computer and use it in GitHub Desktop.
top 5 buyers
DECLARE @customerordersinput string = "/Data/Meny/Output/customerorders.csv";
DECLARE @cvsout string = "/Data/Meny/Output/top5buyers.csv";
@customersorders =
EXTRACT CustomerId int,
CustomerFirstName string,
CustomerLastName string,
ProductName string,
ProductPrice int,
Quantity int
FROM @customerordersinput
USING Extractors.Csv(encoding: Encoding.UTF8);
@ds =
SELECT c.CustomerId AS customerid, ANY_VALUE(c.CustomerFirstName) AS firstname, ANY_VALUE(c.CustomerLastName) AS lastname, SUM(c.ProductPrice) AS total, COUNT(Quantity) AS NumberOfOrders
FROM @customersorders AS c
GROUP BY c.CustomerId
ORDER BY total DESC
FETCH 10 ROWS; ;
OUTPUT @ds
TO @cvsout
USING Outputters.Csv(encoding:Encoding.UTF8, quoting: false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment