sql数据库中有大量数据,配合Navicat软件好看,下面现根据指定要求创建视图表:
1、主外键表
2、两个表的某些数据合并
3、合并条件:a.取特定值。b.主表的不重复。c.某一段时间的数据。d.临时表生成temp_tbl很重要
tbl_a是外键表,tbl_b是主键表。temp_tbl是临时表
sql字段----time:时间字段。其他.后面的都是对应字段
select `tbl_a`.`time` AS `time`,`tbl_a`.`id` AS `id`,`tbl_a`.`card` AS `card`,`temp_tbl`.`lot` AS `lot`,`tbl_a`.`bi` AS `bi`
from (`tbl_a` left join (select `tbl_b`.`card` AS `card`,`tbl_b`.`lo` AS `lo` from `tbl_b` where `tbl_b`.`pk_idx` in (select max(`tbl_b`.`idx`)
from `tbl_b` group by `tbl_b`.`card`)) as `temp_tbl` on((`temp_tbl`.`card` = `tbl_a`.`card`)))
where (`tbl_a`.`time` between '2022-06-15' and '2022-06-30')