Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL:Summenliste für mehrere Bedingungen in einer SQL-Anweisung

Verwenden Sie den mysql GROUP BY-Befehl. Völlig ungetestetes Codebeispiel:

select sum(x) as "sum", date as "date" from (
   select distinct a.id as ID, a.dur as x, DATE(FROM_UNIXTIME(rtime)) as date from b_c 
      inner join c on b_c.c_id = c.id 
      inner join a on c.id = a.c_id 
      inner join a_au on a.id = a_aud.id 
      inner join d on a_au.rev = d.rev 
      where 
         b_c.b_id = 30 and 
         a_au.stat != 1
) AS SubSelectTable
group by date;

Siehe:http://dev.mysql.com /doc/refman/5.0/en/group-by-functions.html