【发布时间】:2021-07-13 08:48:08
【问题描述】:
我需要帮助才能找到去年按产品类别划分的销售额增长
表格是这样的
Tablename- SUPERSTOREDATABASE
|----------|---------------|--------|-------------|----------|-----------|-----------|
| OrderID |ProductCategory| Date |ProductName | Sales |Quantity | Profit |
|----------|---------------|--------|-------------|----------|-----------|-----------|
| 12 | Furniture |2/2/2018| Table | $30 | 2 | 10 |
|----------|---------------|--------|-------------|----------|-----------|-----------|
返回表:我正在尝试排除重新调整的项目
|------------------|-------------------|
| OrderID | Returned |
|------------------|-------------------|
| 2 | Yes |
|------------------|-------------------|
我需要写查询来得到这个输出
|------------------|-------------------|
| ProductCategory |Year on Year Growth|
|------------------|-------------------|
| Furniture | 35% |
|------------------|-------------------|
请帮我写一个查询
我尝试了下面的代码,但它不起作用
select year(ORDERS.ORDERDATE) as year,
sum(case when year(ORDERS.ORDERDATE) = 2019 then ORDERS.SALES else 0 end) as price_2019,
sum(case when year(ORDERS.ORDERDATE) = 2018 then ORDERS.SALES else 0 end) as price_2018
from SUPERSTOREDATABASE.PUBLIC.ORDERS
left join SUPERSTOREDATABASE.PUBLIC.RETURN on ORDERS.ORDERID = RETURN.ORDERID
group by year(ORDERS.ORDERDATE)
order by max(year(ORDERS.ORDERDATE));
【问题讨论】:
-
你描述了一张桌子。您的查询有两个。您尚未定义 YOY 增长的含义,也没有定义您的查询存在的问题。
-
抱歉刚刚编辑