Teradata SQL Cheat Sheet _ Free Download – ETL with SQL
Teradata SQL Cheat Sheet _ Free Download – ETL with SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 1/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 2/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) primary index(col2);
https://etl-sql.com/teradata-sql-cheat-sheet/ 3/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 4/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
FROM
WAREHOUSE
WHERE
w_state = 'KS' with no data primary index (w_warehouse_id);
https://etl-sql.com/teradata-sql-cheat-sheet/ 5/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
SQL
col5 char(10),
col6 varchar(10),
col7 date,
col8 timestamp,
col9 time,
col10 decimal(10, 2),
col11 number(10, 2),
col12 float
) primary index(col2);
ALTER table
warehouse
ADD
w_warehouse_new varchar(30),
ADD
w_warehouse_new2 varchar(30);
ALTER table
warehouse
DROP
w_warehouse_new,
DROP
w_warehouse_new2;
ALTER table
warehouse RENAME w_warehouse_name to w_wh_nm;
https://etl-sql.com/teradata-sql-cheat-sheet/ 7/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
SELECT
SELECT
*
https://etl-sql.com/teradata-sql-cheat-sheet/ 8/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
from
WAREHOUSE sample 10;
SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state = 'TN'
OR w_state = 'VA';
https://etl-sql.com/teradata-sql-cheat-sheet/ 11/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
SQL
SELECT
*
FROM
WAREHOUSE
WHERE
w_state like 'T % ';
WAREHOUSE;
SELECT
tb1.w_warehouse_sk,
tb1.w_warehouse_id,
tb1.w_city
FROM
WAREHOUSE tb1;
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
COALESCE(w_city, 'Not Available') as w_city
FROM
WAREHOUSE;
https://etl-sql.com/teradata-sql-cheat-sheet/ 14/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
43 INNER JOIN
SQL
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
INNER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';
https://etl-sql.com/teradata-sql-cheat-sheet/ 15/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
SQL
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
RIGHT OUTER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1 FULL
OUTER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';
47 SELF JOIN
SQL
select
tb1.w_warehouse_sk,
tb1.w_warehouse_name
https://etl-sql.com/teradata-sql-cheat-sheet/ 16/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
from
warehouse tb1,
warehouse tb2
where
tb1.w_warehouse_id = tb2.w_warehouse_id
and tb1.w_state = tb2.w_state
and tb1.w_warehouse_sk = 1;
select
tb1.w_warehouse_name,
_tb1.w_state,
tb1.w_city
from
warehouse tb1
left outer join inventory tb2 on tb1.w_warehouse_sk =
tb2.inv_warehouse_sk
where
tb2.inv_warehouse_sk is null;
https://etl-sql.com/teradata-sql-cheat-sheet/ 17/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
select
w_warehouse_name,
w_state,
w_city,
row_number() over(
partition by w_zip
order by
w_warehouse_sq_ft desc
) as w_warehouse_no
from
warehouse;
https://etl-sql.com/teradata-sql-cheat-sheet/ 18/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
w_city as w_city
FROM
WAREHOUSE
where
w_state = 'Virginia'
UNION
SELECT
w_warehouse_sk as w_sk,
w_warehouse_id as w_id,
w_city as w_city
FROM
WAREHOUSE
where
w_state = 'Texas';
SELECT
CURRENT_DATE;
https://etl-sql.com/teradata-sql-cheat-sheet/ 19/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
SELECT
CURRENT_DATE + INTERVAL '5' YEAR;
57 Subtract 2 dates
SQL
SELECT
cast('2019 - 12 - 31' as date) – cast('2019 - 04 - 01' as
date);
select
*
from
dbc.tablesV
where
tablename = 'warehouse';
select
*
from
dbc.tablesV
where
databasename = 'tpcds'
and tablekind in ('T', 'O');
https://etl-sql.com/teradata-sql-cheat-sheet/ 21/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
select
databasename,
tablename,
sum(currentperm) as total_size_bytes
from
dbc.tablesize
where
tablename = 'warehouse'
and databasename = 'tpcds'
group by
databasename,
tablename;
https://etl-sql.com/teradata-sql-cheat-sheet/ 22/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
select
session
);
EXPLAIN
select
tb2.d_date,
tb1.ss_quantity,
tb1.ss_wholesale_cost,
tb1.ss_list_price,
tb1.ss_sales_price
from
store_sales tb1
INNER JOIN date_dim tb2 on tb1.ss_sold_date_sk =
tb2.d_date_sk
where
tb2.d_date between '2020 - 01 - 01'
and '2020 - 12 - 31';
SQL
INSERT into employee(
Name, City, County, State, Zip, Country
)
SELECT
Name,
City,
County,
State,
Zip,
Country
from
stg_employee
where
zip = 75000
and country = 'France';
https://etl-sql.com/teradata-sql-cheat-sheet/ 24/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 25/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
https://etl-sql.com/teradata-sql-cheat-sheet/ 26/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
DELETE from
employee;
If you want me to add few more SQL scenarios, feel free to leave
comments and I will include those SQL scenarios too.
https://etl-sql.com/teradata-sql-cheat-sheet/ 27/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
John says:
MARCH 14, 2023 AT 12:09 AM
Hi, Thank you for this. I have made ANKI flashcards from these would you mind
if I shared them?
Reply
Osic says:
MARCH 31, 2022 AT 2:39 AM
Reply
Aniket says:
OCTOBER 1, 2021 AT 12:28 PM
Thank you so much for sharing this wonderful content. I am fresher and have
just transitioned from Campus to Corporate life and have been given Data
Integration domain where I will be required to work on Teradata SQL Assistant
and Informatica Powercenter. Please share more of your experiences with us, it
would be very helpful.
Reply
Prerana says:
JUNE 3, 2021 AT 3:56 PM
https://etl-sql.com/teradata-sql-cheat-sheet/ 28/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
Reply
Abhishek says:
MAY 23, 2021 AT 8:39 PM
Reply
Raj says:
MAY 24, 2021 AT 9:31 AM
Reply
Sonia says:
DECEMBER 12, 2019 AT 3:45 AM
I need the years 2019 and 2020 to look like '2019-20' in a integer field which I
cannot change the data type. Someone suggested using trim and substring.
Can you please help me. Thanks
Reply
TestUser says:
JUNE 16, 2020 AT 2:21 PM
Use left cast and right cast for two dates and concatenate two dates into
one.
E.g. select concat(left(cast('2019-6-16' as varchar(23)), 5),right(cast('8-17-
2020' as varchar(25)), 2));
Reply
https://etl-sql.com/teradata-sql-cheat-sheet/ 29/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
Bhargav says:
SEPTEMBER 24, 2019 AT 6:44 PM
need interview based teradata sql queries and all utilities with an example,.
Reply
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email * Website
Save my name, email, and website in this browser for the next time I
comment.
https://etl-sql.com/teradata-sql-cheat-sheet/ 30/31
8/19/23, 2:56 PM Teradata SQL Cheat Sheet | Free Download – ETL with SQL
Post Comment
https://etl-sql.com/teradata-sql-cheat-sheet/ 31/31