|
SELECT DISTINCT SQL_CALC_FOUND_ROWS c.child_id, c.child_archive, c.child_name, c.child_birth, c.child_birth_class, c.child_lunar_birth, c.org_id, c.child_level, c.child_status, c.child_sex,
p.parent_id, p.parent_name, p.parent_mobile, p.parent_tel,
IF(DATEDIFF(timestampadd(year, (YEAR(NOW())-YEAR(from_unixtime(c.child_birth))), from_unixtime(c.child_birth)), NOW())>=0, DATEDIFF(timestampadd(year, (YEAR(NOW())-YEAR(from_unixtime(c.child_birth))), from_unixtime(c.child_birth)), NOW()), DATEDIFF(timestampadd(year, (YEAR(NOW())-YEAR(from_unixtime(c.child_birth))+1), from_unixtime(c.child_birth)), NOW())) birth
FROM (child as c)
LEFT JOIN child_folder cf on cf.child_id=c.child_id and cf.user_id=2
LEFT JOIN parent as p ON p.parent_id=c.parent_id
LEFT JOIN child_fin_class as cfc ON cfc.child_id=c.child_id
LEFT JOIN financial_class as fc ON fc.financial_class_id=cfc.financial_class_id and fc.class_type_id=1
where cf.folder_id is null
ORDER BY c.child_id desc
LIMIT 2000;
其中左连接那些ID都已加索引 |
|