More func
This commit is contained in:
27
sql/CFY.sql
Normal file
27
sql/CFY.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
WITH const as (select "%ROBOSHOT%" as target)
|
||||
SELECT
|
||||
description,
|
||||
-- year,
|
||||
-- month,
|
||||
sum(revenue),
|
||||
sum(quantity)
|
||||
from
|
||||
data
|
||||
where
|
||||
description like const.target
|
||||
and year = 2021
|
||||
and month BETWEEN 7
|
||||
and 9
|
||||
group by
|
||||
description;
|
||||
select
|
||||
description,
|
||||
sum(revenue),
|
||||
sum(quantity)
|
||||
from
|
||||
data
|
||||
where
|
||||
description like const.target
|
||||
and year = 2021
|
||||
and month BETWEEN 7
|
||||
and 9;
|
||||
64
sql/get_top.sql
Normal file
64
sql/get_top.sql
Normal file
@@ -0,0 +1,64 @@
|
||||
SELECT
|
||||
description,
|
||||
sku,
|
||||
level2,
|
||||
level3,
|
||||
rev,
|
||||
qty,
|
||||
trend
|
||||
from
|
||||
(
|
||||
SELECT
|
||||
*,
|
||||
ROW_NUMBER () OVER (
|
||||
PARTITION BY level2
|
||||
ORDER BY
|
||||
SUM(revenue) DESC
|
||||
) rownum,
|
||||
SUM(revenue) OVER (PARTITION BY level2) total,
|
||||
ROUND(SUM(revenue), 2) as rev,
|
||||
SUM(quantity) as qty,
|
||||
trend
|
||||
FROM
|
||||
(
|
||||
select
|
||||
*,
|
||||
cast(past as float) / 3 as past,
|
||||
round(
|
||||
cast(present as float) /(cast(past as float) / 3.0),
|
||||
2
|
||||
) as trend
|
||||
from
|
||||
(
|
||||
select
|
||||
*,
|
||||
sum(quantity) FILTER (
|
||||
WHERE
|
||||
year = %[1]s
|
||||
and month between %[3]s
|
||||
and %[4]s
|
||||
) over (PARTITION BY description) as past,
|
||||
sum(quantity) FILTER (
|
||||
WHERE
|
||||
year = %[1]s
|
||||
and month = %[2]s
|
||||
) over (PARTITION BY description) as present
|
||||
from
|
||||
data
|
||||
)
|
||||
)
|
||||
where
|
||||
year = %[1]s
|
||||
and month = %[2]s
|
||||
GROUP BY
|
||||
description
|
||||
ORDER BY
|
||||
total DESC
|
||||
)
|
||||
WHERE
|
||||
rownum <= 10
|
||||
and rev > 0
|
||||
order by
|
||||
(sum(rev) over (
|
||||
partition by level2
|
||||
)) desc;
|
||||
11
sql/schema.sql
Normal file
11
sql/schema.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
description text,
|
||||
sku text,
|
||||
level2 text,
|
||||
level3 text,
|
||||
revenue float,
|
||||
cost float,
|
||||
quantity integer,
|
||||
year integer,
|
||||
month integer
|
||||
);
|
||||
Reference in New Issue
Block a user