表1:
id    projecName    reportID
1      火电                  1
2      水电                  1
3      风电                  1
4      火电                  2
5      水电                  2
6      核电                  2
表2:
id    time
1     2016年04月
2     2016年05月想查出来2016年04月上报的projectName,但是05月份没有上报的
即:
id  projectName  
3   风电
mysql数据库,表2的id 对应的表1 reportID,查询2016年04月上报的工程,但是2016年05月没有上报的
实际情况的表每个月上报的数据在5000条左右

解决方案 »

  1.   

    select id ,projectName from table1 a , table2 b where a.reportId = b.id and b.time = '2016年04月'
      

  2.   

    select projecName
    from 表1 a inner join 表2 on reportID=表2.id
    where  time='2016年04月'
    and not exists (select 1 from 表1 inner join 表2 on reportID=表2.id where  time='2016年05月' and projecName=a.projecName)
      

  3.   

    select 表1.*  from 表1,表2 where 表2.time='2016年4月' and 表1.reportid=表2.id