Skip to content
Advertisement

Tag: sql

Window Function for First Instance in Repeating Time Periods

I’m trying to translate the logic below into one or more SQL statements: Find the first occurrence of a given event for a user If the user has any additional events on that day or 30 days after, exclude those events. Keep only the first event. 30 days after the original event, you may consider new events, but the original

How can i change SQL date format to: 12th Jun 2021. (as example)

So, I’m trying to insert data from .csv file, but because of the date format I’m using – import causes it to set to 00-00-0000 import settings: format – CSV using load data (otherwise it causing errors and failing to import) Specific format options: none Errors I’m receiving after import: Data truncated for column… my_date sets to 0000-00-00, even with

Call stored procedure in Snowflake query

I have a stored procedure, called SP_CALC_BUCKET, defined. I can call it like so: and this works, and returns the result I expect. However, if I try to call this stored procedure for each row returned from a SELECT statement: I get the following error: Unknown user-defined function SP_CALC_BUCKET Clearly, the Syntax is informing Snowflake that it should look for

How do I get column names of two tables at a time

How do I get the column name of two tables in a single query ? This works for single table. But if I try This throws error. Answer Different queries will be put together using UNION ALL (or UNION only if it’s necessary to exclude identic values which appear in both queries): Since you want to get data from the

How to return rows containing decimals in a range

I have the following table: Rows Decimals First 1.1.1.3.2 Second 16.1.1.1.89.1 Third 3.1.1.1.177.2 Fourth 1.1.1.1.178.3 I only want to return the rows where the second to last decimal is between 0.7 to 0.94 (inclusive), but all the other numbers can contain any value. For the above table, this would be only the second row. How can I specify my query

How to do conditional aggregate based on values of another column?

I have a table called device_data that looks like below It basically stores the packet drops, jitter, latency on a minute basis. Now there is another column called alert that holds the value HIGH, MEDIUM and LOW based on a threshold and holds empty string if the threshold is not met. Now I do an hourly average on the table,

What should I do to join two columns with different name but has the same data type, so that I can get something I need from one of the table?

I have two table, [table a] and [table b]. So basically, I need work_week from [table a] therefore I want to join the columns together, shift_begin_datetime from [table a] and shift_start_datetime from [table b] as both of them have the same data type but they have different name. I want both of the column to be renamed as shift_start_dt and

Advertisement