mardi 11 septembre 2018

MySQL: Comparing date using IF condition in SELECT statement

I have a query:

SELECT DISTINCT db1.locationDetails.locationUID,
    db1.locationDetails.locationName,
    MAX(db2.HealthData.Date_Time),
    db2.HealthData.memUsage,
    IF(DATE(db2.HealthData.Date_Time) = '2018-09-12', "ON", "OFF") AS Status
FROM db1.locationDetails
LEFT JOIN db2.HealthData
ON db1.locationDetails.locationUID = db2.HealthData.locationID
GROUP BY db1.locationDetails.locationUID

Based on my understanding, the 'Status' column will show "ON" if the Date is equals to 2018-09-12 but somehow it always returns "OFF" regardless of whether the value in the Date_Time column is equal to the Date value specified in the query.

Can anyone tell me what is wrong here? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire