sql >> Database >  >> RDS >> Mysql

mysql-query:toon overzicht van alle gedane betalingen en totaal van facturen op datum

select
  x.date,
  sum(x.invoiceTotal) as invoiceTotal,
  sum(x.paymentsMade) as paymentMade
from
 (select
   i.date, 
   sum(i.rate * i.quantity /*?*/) as invoiceTotal,
   null as paymentMade    
 from
   invoice i
   inner join invoiceitem ii on ii.invoiceId = i.invoiceId
 group by
   i.date
 union all
 select
   p.date,
   null as invoiceTotal,
   sum(p.amount) as paymentMade    
 from
   payment p
 group by
   p.date) x
group by
  x.date
order by
  x.date


  1. PHP/MySQL Like-knop

  2. Voordelen van MySQLi boven MySQL

  3. Scheidingsgraden Query

  4. Hoe tafels te vergrendelen met codeigniter?