Предыдущий ответ не работает, он отвечает 33% Эта работа отлично:
select 100.0 * sum(case when cnt = 1 then sumQty else 0 end) / sum(sumQty) as 'single Order'
,100.0 * sum(case when cnt <> 1 then sumQty else 0 end) / sum(sumQty) as 'multiple Order'
from
(
select
OrderID
,sum(Quantity) as sumQty -- not needed for the final result
,count(*) as cnt
from _ds_test_ac
group by OrderId
) as dt
Если вы хотите в две строки, вы можете сделать:
select cnt = 1 as 'IS Single', 100.0 * sum(sumQty) / tot as 'percent'
from
(
select
OrderID
,sum(Quantity) as sumQty -- not needed for the final result
,count(*) as cnt
from _ds_test_ac
group by OrderId
) as dt join
(
select sum(Quantity) as tot
from _ds_test_ac
) dtot
group by 1