Category Archives: T-SQL

Windows functions in PostgresQL

1. Setting up postgresql on Mac OS Install postgresql: brew install postgresql Start postgres: brew services start postgresql Login to postgres shell to create user: /usr/local/bin/psql -d postgres Create the user: CREATE USER user PASSWORD ‘password’; If you use a … Continue reading

Posted in Data Engineering, SQL Server, T-SQL | Leave a comment

T-SQL Window functions syntax

Window functions are an advanced and powerful feature of the T-SQL language. I will give a few tips on how to use and examples on the AdventureWorks2014 OLTP database. Here I will give some notes on how to use them: … Continue reading

Posted in Data Engineering, SQL Server, T-SQL | Leave a comment

Advanced T-SQL: Best way to find the last 3 orders a customer made

INTRODUCTION AND PROBLEM STATEMENT Assuming we have two tables in our database, Customers and orders, our goal is to find the last three orders the customer made. The query should output 3 columns: custid, orderid and orderdate. You can also … Continue reading

Posted in Data Engineering, SQL Server, T-SQL | Leave a comment