我有 4 個“with”子句表,如下所示
with total_sales as (select sum("REVENUE") as summ from sql_sales) ,
total_items as (select count("ID_ORDER") as oo from sql_sales) ,
order_per_country as (select c."COUNTRY" as country, count(s."ID_ORDER") as orders
from sql_sales s
join sql_country c on s."ID_SELLER_COUNTRY" = c."ID_COUNTRY"
group by c."COUNTRY") ,
revenue_per_country as (select c."COUNTRY" as country, sum(s."REVENUE") as REVENUE
from sql_sales s
join sql_country c on s."ID_SELLER_COUNTRY" = c."ID_COUNTRY"
group by c."COUNTRY")
現在我想顯示帶有 2 列(每個國家/地區)和(每個國家/地區的收入/所有國家/地區的總收入)的決賽桌,但我不知道如何
uj5u.com熱心網友回復:
您使查詢變得相當復雜,您可以使用基本的 sql 聚合來解決它:
select
c.COUNTRY as country,
sum(s.REVENUE)/(select sum(REVENUE) as total_revenue from sql_sales) as Percentage
from sql_country c
join sql_sales s
on s.ID_SELLER_COUNTRY = c.ID_COUNTRY
group by c.COUNTRY
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/411511.html
標籤:
