SELECT * From `users` AS `User`
LEFT JOIN `selections` AS `Selections` ON (`Selections`.`user_id` = `User`.`id`)
LEFT JOIN `clients` AS `Client` ON (`Client`.`id` = `Selections`.`client_id`)
LEFT JOIN `client_stats` AS `ClientsStat` ON (`ClientsStat`.`date` = """DATE1""")
问题是我想在 ClientsStat 中获取某些字段的值,其中 date = "DATE1" 减去相同的字段但日期为 #2 但我不确定在 LEFT JOIN 中如何做到这一点。我尝试对同一个表进行另一个 LEFT JOIN 并重命名并减去但执行时间非常长,所以我想我的方法很糟糕。
编辑:
我的结果是这样的:
USER => fields...
SELECTIONS => fields...
CLIENTS => fields..
CLIENT_STATS => field x,y,z on date = date 1
等等。
我想要这个:
USER => fields
USERSELECTIONS => fields...
CLIENTS => fields..
CLIENT_STATS => field x,y,z when client_stats.date = date1 MINUS field x,y,z when client_stats.date = date2
等等