datacamp / antlr-tsql Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU Affero General Public License v3.0
License: GNU Affero General Public License v3.0
These should not have any Unshaped nodes...
DONE?!
SELECT TOP 10 PERCENT Name
FROM SalesLT.Product
SELECT * FROM SalesLT.Customer;
SELECT Title, FirstName FROM SalesLT.Customer;
SELECT Title + ' ' + LastName FROM SalesLT.Customer;
SELECT CAST(CustomerID AS varchar) + ': ' + CompanyName AS CustomerCompany
FROM SalesLT.Customer;
SELECT CONVERT(nvarchar(30), OrderDate, 102) AS OrderDate
FROM SalesLT.SalesOrderHeader;
see visual_checks.yml:
function_call:
# aggregate_windowed_function
- "COUNT(ALL id = 1) OVER ( PARTITION BY a + b ORDER BY a)"
- "COUNT(*)"
- "AVG ( ALL id )"
- "GROUPING_ID ( a, b )"
# ranking windowed_function
- "RANK () OVER ( PARTITION BY a + b ORDER BY a)"
- "NTILE ( a + b )"
# standard_call
- "COALESCE ( a, b )"
- "BINARY_CHECKSUM (*)"
- "DATEADD ( a, 1 + 1, 2 + 2)"
- "RIGHT ( 1 + 1, 2 + 2 )"
# simple_call
- "SESSION_USER"
# cast_call
- "CAST ( a as varchar )"
From #29
The Vagrantfile makes it possible to use the graphical tools that come with antlr, and also to watch and rebuild when files change. We could definitely replace the second part by using the Dockerfile + volume mounting. The first part (graphical tools) isn't as important now that we are using sqlwhat-viewer. I'll open an issue--if we can volume mount and rebuild on changes with Docker without a lot of fuss, then it seems reasonable to ditch the Vagrantfile.
UPPER, ROUND
see postgres parser
PgQuery.parse("
WITH regional_sales AS (
SELECT region, SUM(amount) AS total_sales
FROM orders
GROUP BY region
), top_regions AS (
SELECT region
FROM regional_sales
WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
)
SELECT region,
product,
SUM(quantity) AS product_units,
SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;
")
SELECT c.CompanyName, oh.SalesOrderID, oh.TotalDue
FROM SalesLT.Customer AS c
JOIN SalesLT.SalesOrderHeader AS oh
ON oh.CustomerID = c.CustomerID;
And the icing on the test cake:
SELECT c.CompanyName, a.AddressLine1, ISNULL(a.AddressLine2, '') AS AddressLine2,
a.City, a.StateProvince, a.PostalCode, a.CountryRegion, oh.SalesOrderID, oh.TotalDue
FROM SalesLT.Customer AS c
JOIN SalesLT.SalesOrderHeader AS oh
ON oh.CustomerID = c.CustomerID
JOIN SalesLT.CustomerAddress AS ca
ON c.CustomerID = ca.CustomerID AND AddressType = 'Main Office'
JOIN SalesLT.Address AS a
ON ca.AddressID = a.AddressID;
SELECT c.CompanyName
FROM SalesLT.Customer AS c
JOIN SalesLT.CustomerAddress AS ca
ON c.CustomerID = ca.CustomerID
JOIN SalesLT.Address AS a
ON ca.AddressID = a.AddressID
WHERE ca.AddressType = 'Main Office'
INTERSECT
SELECT c.CompanyName
FROM SalesLT.Customer AS c
JOIN SalesLT.CustomerAddress AS ca
ON c.CustomerID = ca.CustomerID
JOIN SalesLT.Address AS a
ON ca.AddressID = a.AddressID
WHERE ca.AddressType = 'Shipping'
ORDER BY c.CompanyName;
common table expressions all have with_expression
in them. Like so,
select_statement
: with_expression? query_expression order_by_clause? for_clause? option_clause? ';'?
;
Should move it out, like rule: with_expression? common_table_expression ...
primative_expression, look out for constants with a sign in front of them:
constant
: STRING // string, datetime or uniqueidentifier
| BINARY
| sign? DECIMAL
| sign? (REAL | FLOAT) // float or decimal
| sign? dollar='$' (DECIMAL | FLOAT) // money
;
TODO:
Case Example:
SELECT SalesOrderID, OrderDate,
CASE
WHEN ShipDate IS NULL THEN 'Awaiting Shipment'
ELSE 'Shipped'
END AS ShippingStatus
FROM SalesLT.SalesOrderHeader;
@sumedh10 is working on a Transact-SQL course but there are some queries that result in unshaped nodes. Idealy, we can turn these into shaped nodes that can be easily 'walked' with check_node
and check_edge
.
--First create the variable and assign a datatype
DECLARE @counter int
--Assign a value to the variable using SET
SET @counter = 20
--Create a loop to run until @counter = 30
WHILE @counter < 30
--Loop code starting point
BEGIN
PRINT @counter
SELECT @counter = @counter + 1
-- Loop finish
END
--Create a Cursor variable
DECLARE UpdateCursor CURSOR FOR
--Select statement containing values to be processed
SELECT Recordid, CoronaryArteryDisease
FROM Artery
--Start looping through the records in the query loop
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Kidney SET CoronaryArteryDisease = @CoronaryArteryDisease
WHERE Recordid = @recordid
FETCH NEXT FROM UpdateCursor INTO @recordid, @CoronaryArteryDisease
END
UPDATE SalesLT.Customer
SET EmailAddress = NULL
WHERE CustomerID % 7 = 1;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.