SQL连接不包括空值

时间:2015-02-23 17:01:27

标签: mysql

我试图找到模型飞机737的最小年份 我在年份列中获得空值

SELECT m.name
     , m.n_number
     , m.mfr_mdl_code
     , MIN(m.year_mfr) min_year
     , a.model
     , a.code
  FROM master m
  JOIN acftref a
    ON m.mfr_mdl_code = a.code
 WHERE a.model = 737
 ORDER
    BY m.year_mfr IS NOT NULL
 LIMIT 10;

1 个答案:

答案 0 :(得分:0)

您错过了日期字段的限制。请尝试以下方法:

select master.name
,master.n_number
,master.mfr_mdl_code
,min(master.year_mfr) as min_year
,acftref.model
,acftref.code
from master
join acftref on master.mfr_mdl_code=acftref.code
where acftref.model=737
and master.year_mfr is not null
order by master.year_mfr
limit 10;