mysql数据库中的多表联查
在项目中遇见了mysql库的多表联查,记录下来,供以后查阅。
select a.slzgh as Zgh,c.username as Xm,a.slksh as Ksh,d.Ksmc,a.Ffdate,b.Sortid,b.Sortname,sum(b.Silnum) as Silnum from offmate a inner join offmatedetail b on a.contentid=b.contentid left join user c on a.slzgh=c.userid left join ks d on a.slksh=d.ksh group by a.slzgh where a.sflq=2 and b.sortid='"+sortid+"' and a.ffdate between '"+sdate+"' and '"+edate+"'" 前面两个表提供主要数据,后面两个表提供单项名称。 根据id号和日期区间来查询数据。