Microsoft SQL Server - Percentages of orders -


i'm training on northwind sample database , got task do: "create query returns: companyname, orderid, saleamount (value of order), percentage value of order, total value of customers orders.

i did it, works fine want add else: i want add field show percentage share of individual order comaring total value of orders - sum(saleamount)

i did this:

select   companyname,   orderid,   saleamount,   cast(100 * saleamount / sum(saleamount) on (partition companyname) decimal(5, 2)) 'percent',   sum(saleamount) on (partition companyname) total,   (select     sum(saleamount) całość_zamówienia   dbo.[sales totals amount])   suma_całkowita,   cast(100 * saleamount / sum(saleamount) on (partition companyname) decimal(11, 2)) 'test' dbo.[sales totals amount] group companyname,          orderid,          saleamount 

but shows stupid things, can me please? : )

try this:

 select companyname, orderid, saleamount,         cast(100 * saleamount / sum(saleamount) over(partition companyname) decimal(5,2)) 'percent',         sum(saleamount) over(partition companyname) total,         (select sum(saleamount) całość_zamówienia dbo.[sales totals amount]) suma_całkowita         ,cast(100 * sum(saleamount) over(partition companyname)/ (select sum(saleamount) dbo.[sales totals amount])  decimal(11,2)) 'test'         dbo.[sales totals amount]          group companyname, orderid, saleamount 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -