Mysql filling in missing dates

前端 未结 2 1907
悲哀的现实
悲哀的现实 2020-12-22 06:35

I have the following query

SELECT * 
FROM attend
RIGHT OUTER JOIN noattend ON attend.date = noattend.date2
WHERE attend.date
BETWEEN \'2010-02-01\'
AND \'201         


        
相关标签:
2条回答
  • 2020-12-22 07:16

    If you say that noattend is a table with a row for each date, you should use it in WHERE clause:

    WHERE noattend.date2 BETWEEN (.....
    

    And I think it's more clear to use LEFT JOIN :

    SELECT * 
    FROM noattend
    LEFT OUTER JOIN attend ON (attend.date = noattend.date2 AND attend.customerid =1)
    WHERE noattend.date2
    BETWEEN '2010-02-01'
    AND '2010-04-01'
    ORDER BY date DESC 
    LIMIT 0 , 30
    
    0 讨论(0)
  • 2020-12-22 07:17

    You need to get rid of the SELECT * and list your column names instead. Where you want the date to be, use the field noattend.date2, not attend.date. Attend.date will be NULL (blank) for those extra rows created to fill in your "missing" dates.

    Something like:

     SELECT attend.id, attend.name, noattend.date2
     FROM . . .  (continue your code here)
    
    0 讨论(0)
提交回复
热议问题