Creating a column in dataset for later filter use (mysql) I have a date column (format: 14.05.2018) and a count of sales. I would like to create an extra column that from the current date perspective flags fields that are +/-6 days from today. The following query does not work quite well, the column is empty
select `Date`, `Sales`,
(CASE 
    when DAY(CURRENT_DATE())-6 &lt;= DAY(`Date`)
            AND DAY(CURRENT_DATE())-6 &gt;=  DAY(`Date`) then '1'
    when DAY(CURRENT_DATE())-6 &gt; DAY(`Date`)
            AND DAY(CURRENT_DATE())-6 &lt; DAY(`Date`) then '0'
 end as Flag)
from sales;
Data should obly be posted as text or ddl, that makes the live easier for all of us
Basically you query can be reduced to an If clause, as seen below, but as i tested it again, i noticed, mysql doesn't like you date format so it has to be converted to a date, so that the code can properly work.
Schema (MySQL v5.6)
CREATE TABLE sales (
  `Date` VARCHAR(10),
  `Sales` INTEGER
);

INSERT INTO sales
  (`Date`, `Sales`)
VALUES
  ('14.05.2018', '8046'),
  ('11.02.2020', '4564'),
  ('25.07.2018', '6648'),
  ('25.08.2020', '7785'),
  ('01.09.2020', '8788'),
  ('30.04.2018', '4655'),
  ('22.09.2019', '6867'),
  ('09.12.2016', '6868'),
  ('26.10.2018', '6785'),
  ('01.09.2020', '7456'),
  ('12.12.2018', '7456');


Query #1
select `Date`, `Sales`,
IF(CURRENT_DATE() - INTERVAL 6 DAY &lt;= STR_TO_DATE(`Date`,'%d.%c.%Y')
            AND CURRENT_DATE() + INTERVAL 6 DAY &gt;=  STR_TO_DATE(`Date`,'%d.%c.%Y'),1,0) flag
from sales;

| Date       | Sales | flag |
| ---------- | ----- | ---- |
| 14.05.2018 | 8046  | 0    |
| 11.02.2020 | 4564  | 0    |
| 25.07.2018 | 6648  | 0    |
| 25.08.2020 | 7785  | 0    |
| 01.09.2020 | 8788  | 1    |
| 30.04.2018 | 4655  | 0    |
| 22.09.2019 | 6867  | 0    |
| 09.12.2016 | 6868  | 0    |
| 26.10.2018 | 6785  | 0    |
| 01.09.2020 | 7456  | 1    |
| 12.12.2018 | 7456  | 0    |


View on DB Fiddle