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

MySQL:elenco di somme per diverse condizioni in un'istruzione SQL

Usa il comando mysql GROUP BY. Esempio di codice completamente non testato:

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;

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