Bring range data

0

I would like to bring even the ones where there was not value in the query For example;

table data

id    |   valor  |   data
 1    |   5      |   01/10/2018
 2    |   6      |   03/10/2018
 3    |   7      |   04/10/2018
 5    |   8      |   05/10/2018

I would like it when you make an appointment

SELECT * FROM dados WHERE data BETWEEN '01/10/018' AND '06/10/2018'

Come 02/10/2018 and day 06/10/2018 even without the data

id    |   valor  |   data
 1    |   5      |   01/10/2018
      |   null   |   02/10/2018
 2    |   6      |   03/10/2018
 3    |   7      |   04/10/2018
 5    |   8      |   05/10/2018
      |   null   |   06/10/2018  

What is it like?

    
asked by anonymous 29.10.2018 / 19:42

1 answer

0

You need to list the dates in a sub-select and make LEFT JOIN to list all:

SELECT dados.id, dados.valor, datas.data
FROM (
    SELECT '2018-10-01' AS data
    UNION
    SELECT '2018-10-02' AS data
    UNION
    SELECT '2018-10-03' AS data
    UNION
    SELECT '2018-10-04' AS data
    UNION
    SELECT '2018-10-05' AS data
    UNION
    SELECT '2018-10-06' AS data
) AS datas
LEFT JOIN dados ON dados.data = datas.data

If your data column of the dados table is not in the date format, you need to do this:

SELECT dados.id, dados.valor, datas.data
FROM (
    SELECT '01/10/2018' AS data
    UNION
    SELECT '02/10/2018' AS data
    UNION
    SELECT '03/10/2018' AS data
    UNION
    SELECT '04/10/2018' AS data
    UNION
    SELECT '05/10/2018' AS data
    UNION
    SELECT '06/10/2018' AS data
) AS datas
LEFT JOIN dados ON dados.data = datas.data
    
29.10.2018 / 19:50