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-…

MySQL CURDATE() + INTERVAL 1 DAY not returning as should

I am stumped! I have a table that has a field job_date_start — And the DataType is set to DATETIME If I SELECT job_date_start FROM table; from my table the output is: +—————————+ |…

Break periods at the end of the month

SQL Server 2017 CREATE TABLE [TABLE_1] ( PLAN_NR decimal(28,6) NULL, START_DATE datetime NULL, ); INSERT INTO TABLE_1 (PLAN_NR, START_DATE) VALUES (1,’2020-05-01′), (2,’2020-08-01′); …

How can I select the max for a maths operation and also other elements without the max displaying all results

I am trying to find the maximum value of something, while also selecting other attributes at the same time. When i do the max statement on its own, it works as intended, but when I select another …

How to exclude rows with similar columns?

There is a table: | date | action | issue_id | | 2020-12-14 | close | 1 | | 2020-12-15 | close | 1 | | 2020-12-16 | close | 1 | | 2020-12-14 | close | 2 | …

SQL column default value set using row wise operations

Is it possible to set a default value in a SQL column to be consisted of other columns? For example, in the table below is it possible to have the EndDate default to StartDate + NoOfDays? So when …

Get previous months first and last date

I need to query last month data from a database. So I need the first and last date of previous month to be able to make the “between” SQL query. First date starts always from 1 of course, …

Order by with formatted dates, doing it right?

I wanted a mere sanity check because I have a slight feeling I am doing it all wrong. I stripped down the use case to a very simple sample. When formatting a date I need to cast the data in the order …

Get Latest ModifiedDate Joining Multiple Tables

I have 4 tables ProjectTable projectid: INT (pk) modifiedDate: DateTime2 … ProjectFinalizeTable id: INT (pk) projectid: INT (fk) modifiedDate: DateTime2 … ProjectAdditionalTimeTable id: INT (…

Postgres SUM over given time

I am trying to SUM google analytics data over a given time using Postgres. I am not quite sure how to get around a grouping issue. The query you see below returns one column per day. I want to SUM all …