Combine fields from different rows on condition

后端 未结 1 928
走了就别回头了
走了就别回头了 2021-01-27 10:02

Amazon offers their marketplace customers a CSV report which contains information about every article you sold. There are four rows per article, looking like this:



        
相关标签:
1条回答
  • 2021-01-27 10:39

    you can calculate itemprice and itemfees with two queries and join them

    select a.orderid, a.price, b.fees
    from (select orderid, sum(amount) price from report where amounttype='ItemPrice' group by orderid) a
         join (select orderid, sum(amount) fees from report where amounttype='ItemFees' group by orderid) b
         on a.orderid = b.orderid
    

    this asumes there is at least one row with itemprice and one row with itemfees. otherwise you should use an outer join.

    0 讨论(0)
提交回复
热议问题