mardi 23 mai 2017

Using IF output as a variable in MySQL

I have a table alpha has 3 column which id (INT) and time1, time2 (DATETIME)

Now I want to count how many rows in everyday from 2017-04-18 to 2017-05-24 and I tried this query but failed

SELECT IF(time1 < time2, time2, time1) AS d, COUNT(DATE(d)) FROM alpha 
WHERE time1 IS NOT NULL AND time2 IS NOT NULL
AND DATE(d) BETWEEN DATE('2017-04-18') AND DATE('2017-05-24')

please help me fix this. tks a lot

Aucun commentaire:

Enregistrer un commentaire