0% found this document useful (0 votes)
14 views

SQL Cheat Sheet

Uploaded by

Stefan Andrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL Cheat Sheet

Uploaded by

Stefan Andrei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

TRUNC(ACTIVITY_DAY,'D') TO_CHAR(ACTIVITY_DAY,'MM/DD/YYYY') Alw

ays
ADD_MONTHS(ACTIVITY_DAY,-5) LAST_DAY(ACTIVITY_DAY)
Run
ACTIVITY_DAY BETWEEN TO_DATE('{RUN_DATE_YYYYMMDD}','YYYYMMDD')-6 Expl REGION_ID = 1
AND TO_DATE('{RUN_DATE_YYYYMMDD}','YYYYMMDD')
ain
Plan
WAREHOUSE_ID <> 'PHL1'
For Range Partitioned Tab
WAREHOUSE_ID != 'PHL1'
SELECT, GROUP BY, & ORDER BY - Expressions are separated by commas.
Include WHERE clause
WHERE, HAVING and ON - Conditions are separated by AND & OR. WAREHOUSE_ID LIKE 'PH_1'
conditions on all Partitio
WindowsShare: \\Ant\dept\BMVDSA\Books\Inventory_Management\ET
{RUN_DATE_YYYYMMDD} LOWER(ITEM_NAME) LIKE '%banana%'

SELECT a.COLUMN1
SELECT
{FREE_FORM}
TEXTBOOK_TYPE IS NOT NULL
{JOB_PROFILE_ID} DECODE(column, 'M','Y','P','Y','N')
, b.COLUMN1 as “Column B” FROM
{LEGAL_ENTITY_ID}
ASIN IN ('0123456789', 'B008675309')
, COUNT(b.COLUMN6) as COL_SIX {MARKETPLACE_ID}
FROM A_TABLE a WHERE
{REGION_ID} NVL(COLUMN,0) NVL2(COLUMN, 'Y', 'N')
ORDER_TYPE NOT IN (17,8,33)
JOIN B_TABLE b
ON a.COLUMN2 = b.COLUMN3
GROUP BY
QUANTITY BETWEEN 5 AND 500
AND a.COLUMN4 = b.COLUMN4 HAVING
WHERE a.COLUMN4 = 1 COST >= 100 data
AND (b.COLUMN7 IN ('A', 'B', 'C') ORDER BY
OR b.COLUMN8 IS NULL)
GROUP BY a.COLUMN1
;
, b.COLUMN1
HAVING COUNT(b.COLUMN6) > 10
ORDER BY COUNT(b.COLUMN6) DESC
;

Subqu
& tre

A GROUP BY clause is required if your


SELECT clause includes both Aggregate
and NonAggregate Expressions.
datanet.amazon.com
Join Type Efficiency Aggregate Expressions include:
bimetadata.amazon.com
COUNT() SUM()
INNER JOIN – filters results of both tables to only matches HIGH
MIN() MAX() AVG()
between them. MEDIAN() STDDEV()
LEFT OUTER JOIN – returns all results from table on LEFT of the MEDIUM
If a GROUP BY clause is required, it
join, plus any matching results from table on the RIGHT. Used
should include all NonAggregate
only if non-matches in RIGHT table are expected. Expressions from the SELECT clause,
FULL OUTER JOIN – returns all results from both tables, LOW minus any column aliases.
including non matches from both.
CARTESIAN JOIN – joins every row from one table to every row VERY LOW
in another, returning every possible combination.

Subque

You might also like