2015-09-05 143 views
0

我几乎是在mysql中尝试解决此问题的新手。我有两个表在mysql中查找4月份的缺失日期

一个是month_april和第二是month_sales

Month_april

Month_dates    

2015-04-01    
2015-04-02 
2015-04-03 
2015-04-04 
2015-04-05 
2015-04-06 

    . 
    . 
    . 
    . 

2015-04-30 

Month_sales

Month_dates Sale_name 
2015-04-01  Remote 
2015-04-05  Remote 
2015-04-08  Remote 
2015-04-09  Remote 
2015-04-10  Remote 
2015-04-15  Remote 
2015-04-20  Remote 
2015-04-25  Remote 
2015-04-30  Remote 

这是两个表,并有一个产品只有名字“远程”。我需要使用“Sale_name”缺失“Month_sales”表的日期的数据

是否有可能仅使用month_sales表获取数据?如果没有,那么我怎样才能使用这两个表。

我要找的输出这样

Month_dates Sale_name 

2015-04-02  Remote 
2015-04-03  Remote 
2015-04-04  Remote 
2015-04-06  Remote 
2015-04-07  Remote 
2015-04-11  Remote 
2015-04-12  Remote   
2015-04-13  Remote 
2015-04-14  Remote 
2015-04-16  Remote 
2015-04-17  Remote 
2015-04-18  Remote 
2015-04-19  Remote   
2015-04-21  Remote 
2015-04-22  Remote 
2015-04-23  Remote 
2015-04-24  Remote 
2015-04-26  Remote 
2015-04-27  Remote 
2015-04-28  Remote 
2015-04-29  Remote 
+0

有可以追溯到几年表,前几年,像你这样做month_april,只是不把它叫做 – Drew

回答

0

这是不是你想要做什么?

select ma.month_date, 'Remote' as sale_name 
from month_april ma left join 
    month_sales ms 
    on ma.month_date = ms.month_date 
where ms.month_date is null; 
+0

你好戈登。如果你有时间可以看看我的[问题](http://stackoverflow.com/questions/32358431/can-i-make-a-simple-trigger) –

+0

谢谢Gordon Linoff! – roy

0

您可以在日期表上找到left join以查找缺失的日期。

select a.month_dates, s.sales_name 
from month_april a 
left join month_sales s 
on a.month_dates <> s.month_dates 
where s.month_dates is not null; 

Fiddle