left join的第二表中符合条件的第一条记录

表1 parking的数据   通过left join第二表(parking_member_freetime)的第一条记录;重点一点是group by id 

SELECT p.*,f.member_free_starttime,f.member_free_endtime,f.residue_carport,IF(m.id IS NULL,'0','1') AS onlinePay
 FROM parking p LEFT JOIN parking_member_freetime f ON f.`ltd_code`=p.`ltd_code`
AND f.`park_code`=p.`park_code` AND  DATE_FORMAT(NOW(),'%y-%m-%d')=DATE_FORMAT(f.member_free_starttime,'%y-%m-%d')
LEFT JOIN wc_merchant_pay m  ON m.`ltd_code`=p.`ltd_code`AND m.`park_code`=p.`park_code` 
GROUP BY p.id LIMIT 1

 

展开阅读全文

没有更多推荐了,返回首页