SQL code snippets
Explore SparkSQL code snippets to handle time zones, averages, bins, window functions, and conditional logic in the Tellius SQL editor for faster prep.
1. Converting a time column to UTC
SELECT
*,
to_utc_timestamp(origin_timestamp, origin_timezone) AS time_utc
FROM table_name2. Calculating Lag/Lead
Using LAG
SELECT
*,
LAG(Sales) OVER (PARTITION BY Order_Id ORDER BY Date) AS Prev_Sales
FROM table_nameUsing LEAD
3. Creating rolling averages
4. Creating bins/buckets with NTILE
5. Creating an average in the same table
6. Using CASE statements
7. Handling NULLs with COALESCE
8. Date/Time truncation
9. Calculating time differences
Was this helpful?