select
//a在下面指定了是表ZK1,serial是字段名
a.serial,
//b在下面指定了是表ZK2
b.mainnum
from ZK1 as a INNER JOIN ZK2 as b on
//根据标识符查询数据
a.id=b.fid
//按照a表的id的倒序排序
order by a.id desc
select DISTINCT
b.fid, a.serial,b.mainnum
from ZKpump as a INNER JOIN ZKpolling as b
on a.id = b.fid
fid唯一 保留创建时间最晚的一条
where not EXISTS (select 1 from ZKpolling where fid=b.fid and pollingdate>b.pollingdate) ORDER BY b.fid