简体   繁体   中英

sql select query is not functioning properly

I been trying to fix this sql query. The query is suppose count per day. What I been getting is that it currently will display all days as the total count. Instead of counting Five for Monday, it will count all days at the maximum 10. How can I fix my sql query.

 for($setTime = 29; $setTime >= 0; $setTime--){     
 $time = mysql_query("SELECT COUNT(user_id) 
FROM users 
WHERE time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 29 DAY)) 
GROUP BY DAY(UNIX_TIMESTAMP(time))");   

Basically that query will not display the total for each day but instead it will display 28 days days with a total of 10. How can I fix my MySQL Query??

Use DAYNAME if you need to get the count for Monday and so on

SELECT COUNT(user_id)
FROM users
WHERE time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 29 DAY))
GROUP BY DAYNAME(UNIX_TIMESTAMP(time))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM