How To Do Percent/Total in SQL?

前端 未结 4 1590
梦如初夏
梦如初夏 2021-01-07 17:12

I have an typical CUSTOMER/ORDERS set of tables and I want to display the total percentage of sales a particular customer is responsible for. I can get the

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 17:38

    select abc.item_name, sum(amount) as total
      from (select a.item_id, d.applicablefrom, a.item_name, a.final_item_status, d.rate, c.item_name as sub_item_name,
                   b.sub_item_qty as itemqty, (b.sub_item_qty * d.rate) as amount 
              from tblitem_master a,
                   tblitem_master c,
                   tblitem_bom_master b,
                   (select rate, applicablefrom, itemid
                      from tblperiodrates
                     where applicablefrom = (select max(applicablefrom) 
                                               from tblperiodrates
                                              where applicablefrom<='2005-5-18')) as d
             where a.item_id = b.item_id
               And b.sub_item_id = c.item_id
               and b.sub_item_id = d.itemid
               and a.final_item_status='f') as abc
     group by abc.item_name
    

提交回复
热议问题