Mysql
 sql >> Database >  >> RDS >> Mysql

Conteggio MySQL Weekday/Weekend - Parte II

SELECT 
  fname, 
  MONTH(eventDate), 
  SUM(IF(WEEKDAY(eventDate) < 5,1,0)) AS WeekdayCount,
  SUM(IF(WEEKDAY(eventDate) >= 5,1,0)) AS WeekendCount
FROM eventcal AS e
LEFT JOIN users AS u ON e.primary = u.username
GROUP BY fname, MONTH(eventDate);

Vuoi fare le tue aggregazioni (SUM in questo caso) in SELECT e GROUP BY come vuoi che vengano sommate (per nome, per MESE).