Skip to content

Tag: sql

Conversion of time zone in snowflake sql

I am doing a conversion of timezone from current_timestamp to ‘US/Eastern’ in snowflake view. I was able to create the view but when I preview the data I am getting Timestamp ‘US/Eastern’ is not recognized error. I am converting like below: ((CONVERT_TIMEZONE(current_timestamp, ‘…

Spark.sql Filter rows by MAX

Below is part of a source file which you could imagine being much bigger: After the following code: I would like to obtain this result: The aim is to: Select the dates which each cityname has the MAX total (Note, A city can appear twice if they have MAX total for 2 different dates), Sort by total descending, …

Running query against all schemas in Postgres

Context We do schema-based multi-tenancy in our Postgres DB. Each and every schema is associated to a different tenant and will have the exact same structure except for one schema named public. To obtain the list of all the relevant schemas, we can use: Problem We need to periodically clean up a specific tabl…

Dynamic/Customized Week Number

Let us say there is a table which stores data for student’s attendance for classes. The student only need to attend each class once weekly. Hinging on the days_diff column, we decide which weeks the student should get credited for. As usual, each week has 7 days and the end of the week (in days) is divi…