Mysql 左连接多个条件统计

SELECT p.id, p.name, p.projectid, p.userid, p.statu,

(SELECT COUNT(*) FROM model m WHERE p.`name`=m.`name` AND DATE_FORMAT(m.addtime,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') AND m.`projectid` = 1) AS `adds`,

(SELECT COUNT(*) FROM modelt WHERE p.`name`=t.`name` AND DATE_FORMAT(t.arrivetime,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') AND t.`projectid` = 1) AS `arri`

FROM project p

WHERE p.statu = 1 and p.projectid=1

ORDER BY p.id ASC

你可能感兴趣的:(Mysql 左连接多个条件统计)