Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RFID
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Szymon Langer
RFID
Commits
f91b51a4
Commit
f91b51a4
authored
3 years ago
by
Szymon Pawłowski
Browse files
Options
Downloads
Patches
Plain Diff
Cwiczenia SQL lab
parent
95edbbac
Branches
Branches containing commit
No related merge requests found
Pipeline
#2134
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cw.sql
+112
-0
112 additions, 0 deletions
cw.sql
with
112 additions
and
0 deletions
cw.sql
0 → 100644
+
112
−
0
View file @
f91b51a4
-- ITEMID, SUBCLASS, CLASS, DEPARTMENT, BRAND
SELECT
TOP
100
a
.
ITEMID
,
b
.
SubclassName
,
c
.
ClassName
,
d
.
DepartmentName
,
e
.
BrandName
FROM
dw
.
Item
a
JOIN
dw
.
Subclass
b
ON
a
.
SubclassID
=
b
.
SubclassID
JOIN
dw
.
Class
c
ON
b
.
ClassID
=
c
.
ClassID
JOIN
dw
.
Department
d
ON
c
.
DepartmentID
=
d
.
DepartmentID
JOIN
dw
.
Brand
e
ON
d
.
BrandID
=
e
.
BrandID
-- Stylecolor, SUBCLASS, CLASS, DEPARTMENT, BRAND
SELECT
DISTINCT
a
.
StyleColor
,
b
.
SubclassName
,
c
.
ClassName
,
d
.
DepartmentName
,
e
.
BrandName
FROM
dw
.
Item
a
JOIN
dw
.
Subclass
b
ON
a
.
SubclassID
=
b
.
SubclassID
JOIN
dw
.
Class
c
ON
b
.
ClassID
=
c
.
ClassID
JOIN
dw
.
Department
d
ON
c
.
DepartmentID
=
d
.
DepartmentID
JOIN
dw
.
Brand
e
ON
d
.
BrandID
=
e
.
BrandID
ORDER
BY
StyleColor
-- SUBCLASS, CLASS, DEPARTMENT, BRAND
SELECT
TOP
100
b
.
SubclassName
,
c
.
ClassName
,
d
.
DepartmentName
,
e
.
BrandName
FROM
dw
.
Subclass
b
JOIN
dw
.
Class
c
ON
b
.
ClassID
=
c
.
ClassID
JOIN
dw
.
Department
d
ON
c
.
DepartmentID
=
d
.
DepartmentID
JOIN
dw
.
Brand
e
ON
d
.
BrandID
=
e
.
BrandID
-- Sprzedaz dla Galeri Batyckiej za maj 2021 po depach, DEP SLSU
SELECT
e
.
DepartmentName
,
SUM
(
a
.
SLSU
)
AS
SLSU_Total
FROM
demo
.
Sales
a
JOIN
dw
.
Item
b
ON
a
.
ITEMID
=
b
.
ITEMID
JOIN
dw
.
Subclass
c
ON
b
.
SubclassID
=
c
.
SubclassID
JOIN
dw
.
Class
d
ON
c
.
ClassID
=
d
.
ClassID
JOIN
dw
.
Department
e
ON
d
.
DepartmentID
=
e
.
DepartmentID
WHERE
a
.
StoreID
=
(
SELECT
StoreID
FROM
demo
.
Store
WHERE
StoreMale
=
'Galeria Baltycka'
)
AND
a
.
TransactionDate
LIKE
'202105%'
GROUP
BY
e
.
DepartmentName
-- Najlepsze 3 tygodnie dzie po dniu dla stylokoloru \
-- w salonie z najwieksza sprzedaza w trzech najlepszych tygodniach
-- STCL, ITEMID, STORE, Date, EOP, SLS
;
WITH
SLSU_Total_Best_3Weeks
AS
(
SELECT
TOP
1
a
.
StoreID
,
b
.
StyleColor
,
SUM
(
a
.
SLSU
)
AS
SLSU_Total
FROM
demo
.
Best3WeeksPerDay
a
JOIN
dw
.
Item
b
ON
a
.
ITEMID
=
b
.
ITEMID
GROUP
BY
a
.
StoreID
,
b
.
StyleColor
ORDER
BY
SLSU_Total
DESC
)
SELECT
TOP
100
c
.
StyleColor
,
b
.
ITEMID
,
b
.
StoreID
,
b
.
Date
,
b
.
EOPU
,
b
.
SLSU
FROM
demo
.
Best3WeeksPerDay
b
LEFT
JOIN
dw
.
Item
c
ON
b
.
ITEMID
=
c
.
ITEMID
WHERE
b
.
StoreID
=
(
SELECT
StoreID
FROM
SLSU_Total_Best_3Weeks
)
AND
c
.
StyleColor
=
(
SELECT
StyleColor
FROM
SLSU_Total_Best_3Weeks
)
-- Zestawienie tygodni zycia produktu z najepszymi trzema tygodniami
-- - ile bylo przypadkow ze tydzien byl jednym z trzech najlepszych
-- WEEK, CasesCount
-- per STCL gdy jest najlepszym
SELECT
STCL
,
StclWeek
,
SUM
(
CASE
WHEN
WeekRank
=
1
THEN
1
ELSE
0
END
)
AS
CasesCount
FROM
demo
.
Best3WeeksPerWeek
GROUP
BY
STCL
,
StclWeek
ORDER
BY
STCL
,
StclWeek
-- all gdy jest najlepszym
SELECT
StclWeek
,
SUM
(
CASE
WHEN
WeekRank
=
1
THEN
1
ELSE
0
END
)
AS
CasesCount
FROM
demo
.
Best3WeeksPerWeek
GROUP
BY
StclWeek
ORDER
BY
StclWeek
-- all gdy jest jednym z trzech najlepszych
SELECT
StclWeek
,
COUNT
(
*
)
AS
CasesCount
FROM
demo
.
Best3WeeksPerWeek
GROUP
BY
StclWeek
ORDER
BY
StclWeek
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment