How to find the most appropriate date between overlapping date periods in mysql

I`w got an 2 tables with such data: Table 1 id s_id s_date 1 33 2021-03-05 10:36:59 2 33 2021-03-06 10:36:59 3 33 2021-03-09 10:36:59 4 33 2021-03-10 13:36:59 5 33 2021-03-11 12:36:59 6 33 2021-…

Check for overlapped dates on any row of a table Oracle SQL

I have the following schema: CREATE TABLE EPOCA ( ID INT CONSTRAINT PK_EPOCA PRIMARY KEY, NOME VARCHAR(250), DATA_INI DATE CONSTRAINT NN_EPOCA_DATA_INI NOT NULL, …

Create date table of every second between two dates

I need to create a table of every second between two input dates eg between 01/01/2015 00:00:01 and 05/01/2016 00:00:00 So a 3m row expected output that looks like this: Does this need a CLR? …

Why do I get a conversion failed error when I use my attribute on my WHERE clause but it works when I don’t?

Why is my query returning a result when I run the following query: SELECT MAX(CAST(IssueDate as Date)) FROM (SELECT IssueDate FROM [Transient].[Commissions_TIB] WHERE ISDATE(issuedate) = 1 …

Create Missing Data Hive SQL

I have a table that has an activity date of when things change such as 2020-08-13 123 Upgrade 2020-08-17 123 Downgrade 2020-08-21 123 Upgrade Basically this in relation to a line there are 3 …

Why were all rows deleted when trying to delete old rows with date query

I have a table with column name date of type timestamp I’m trying to delete old rows with the following query: delete from my_table where date<(now()-'30 days'::interval) but all rows are deleted. …

Expanding Date Ranges

I want to expand the date ranges in the below “Original Table”. The end result should be the “Resultant Table”. I know that this can be done in sql using dateadd and ctes. However, …

Count distinct per fiscal year and display all dates in query result

DB-Fiddle: CREATE TABLE customers ( id int auto_increment primary key, order_date DATE, customerID VARCHAR(255) ); INSERT INTO customers (order_date, customerID ) VALUES (“2020-01-…

Presto – how is there an alternative to to_char like postgresql?

I need to build a query in presto that could look back the trailing 70 days, the table I am working with is storing the dates in the format of ‘YYYYMMDD’. in postgresql, I can just simply write the …

SQL count distinct # of calls 6 months prior to create date

Am trying to figure out the SQL to: count # of distinct calls made on an account 6 months prior to the account being created I also need to CAST the date field. I’m thinking something like: case …