You either need every working day in your table or you need a separate table with a every day and whether it is a working day or not.
I'm not familiar with mysql, the below is my attempt to translate something that works in MS SQL Server, I'm hoping it will work in mysql.
Below I've assumed your only table is called Table1 and it has every working day in and is the table from your question.
First you need to create a function
CREATE FUNCTION [OffsetDate]
(
@StartDate DATE NULL,
@OffsetDays INT = 0
)
RETURNS DATE
AS
BEGIN
DECLARE @Result DATE
SET @Result = @StartDate
BEGIN
SELECT @Result = distinctDates.Date
FROM (SELECT DISTINCT Table1.Date
FROM Table1
WHERE Table1.Date <= @StartDate
AND Table1.WorkDay = 1) AS distinctDates
ORDER BY distinctDates.Date DESC
LIMIT 1 OFFSET @OffsetDays
END
RETURN @Result
END
Then use this in a query to get your 4th column:
SELECT Table1.Date, Table1.WorkDay, Table1.[Days Back], OffsetDate(Table1.Date, Table1.[Days Back]) AS StartDate
FROM Table1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…