MySQL-根据日期加入 [英] MySQL - Join Based on Date
本文介绍了MySQL-根据日期加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以基于同一日期而不是时间因素来联接两个表?
Is it possible to join two tables based on the same date, not factoring in time?
类似的东西:
...从任命左加入销售 subscriptions.date = sales.date ...
...FROM appointments LEFT JOIN sales ON appointments.date = sales.date...
唯一的问题是它是日期时间字段,所以我想确保它只查看日期而忽略时间
The only problem is it is a datetime field, so I want to make sure it is only looking at the date and ignoring time
推荐答案
您可以这样做:
FROM appointments
LEFT JOIN sales ON DATE(appointments.date) = DATE(sales.date)
但是我很确定它将无法使用索引,因此会非常慢.
But I'm pretty sure it won't be able to use an index, so will be very slow.
最好在每个表中添加一个日期列.
You might be better off adding a date column to each table.
这篇关于MySQL-根据日期加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文