I am trying to accomplish the following table update via an insert for an etl process: Add in a new records that did not exists Update any records that had updates Keep all the records in place that did not change On the table I have a unique_id and an updated_date field when the record was updated ( or could
Tag: sql
How to get the last 7 weeks, 7 months date range from current date PHP?
How can I get the date range of last seven weeks /months from the current date, i have already done with last seven days fetch last seven days, weeks and month sales total grouped by 7 particular days, 7 particular weeks and 7 particular months ex: Last seven weeks Last seven Months The below query I have don…
SQL Query to Update the Start and End Date in a table from a different column where the dates do not match
I need a query which will Update the Start_Date and End_Date in this table. By Checking the Mapping column.When the value of date starts to change that should become the new start and end date. For example : The above two are same till the part 25-NOV-15-15-AUG-22. So our new Start_date for 1st record should …
Select Distinct (case insensitive) on Postgres
This has been asked here and a few other places before but seems like the suggested answers either don’t apply to postgres or don’t work in this situation. I’m looking to select distinct column names, eg: SELECT DISTINCT column_name FROM table_name WHERE … ORDER BY column_name however …
Set a databricks python variable with a %sql statement
The code in cell 1 works just fine. The problem I just don’t know the correct keywords to search to see how I can make the code in cells 2 & 3 work. Basically, in a %sql cell, can I select into a variable that can be later used in a python cell? I realize this may not even be
Ignore Null Bind Variables in SQL
I am trying to create a dynamic SQL Statement which can be used to filter based on several parameters. But one of the caveats is that not all parameters will be available, so could 4 variables or could be 0. This is my attempt at creating this query (small example with only one variable): This however throws …
How to write a single query to run some retrospective aggregation when time window is different for every row?
I am writing some SQL queries to create a dataset for customer churn predictions based on historical service data. Some of the services date back years ago. Small percentage of them churned at some time in the past while others ended up getting renewed. Some of the attributes are based on aggregation of the s…
How to group by two columns in different CASE clauses
I have a query that’s giving me the results I want, but for each item with a given ID_UNIDAD_EXPERIMENTAL there are two rows, one with column “Alt” with a value and column “Dap” with null, and the other one with “Alt” null and “Dap” with a value. My questi…
waitlist in postgres, deadlock
I’m trying to create a waiting list in Postgres. Minimal code: status is important, because I want to be able to notify users when they are applied after waitlisted. But don’t want to notify them based on that they are in the first n position if they wasn’t waitlisted at all. Services are li…
SQL query to consider exactly last 3 email send count and then return the respective click count
I have a table – ‘clicks_plus_noClicks_raw’ like below If customer has not clicked on any of the last 3 emails we sent(exact 3), I want to add the result to final table with count as 0. a@gmail.com & b@gmail.com should be skipped because we dint send them 3 emails yet.The final results s…