sql >> データベース >  >> RDS >> Mysql

mysqlクエリ:行われたすべての支払いの概要と日付ごとの請求書の合計を表示します

    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. Postgresqlの複数の列でWHEREINを実行する

    2. tomcat 7.0.42プーリング、hibernate 4.2、mysqlロックソリッド自動再接続ソリューション

    3. oraclesqlで同等の`showcreatetable`

    4. 複数の行を更新するmysql