-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQUERY.sql
158 lines (139 loc) · 2.9 KB
/
QUERY.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
select * from penjualan;
select * from produk;
select * from customer;
select * from penjualan_ds;
select * from produk_ds;
select * from customer_ds;
select * from penjualan_update_ds;
select * from penjualan_update_fix_ds;
#UPDATE DATA PENYESUAI HARGA YANG RANCU DAN KEMASAN
SELECT
J.id_distributor,
J.id_cabang,
J.id_invoice,
J.tanggal,
J.id_customer,
J.id_barang,
J.jumlah_barang,
J.mata_uang,
J.brand_id,
J.lini,
Ps.harga,
Ps.kemasan
FROM
penjualan J
INNER JOIN
produk_ds Ps ON J.id_barang = Ps.kode_barang;
# export csv sbg penjualan_update_ds
SELECT
id_distributor,
id_cabang,
id_invoice,
tanggal,
id_customer,
id_barang,
jumlah_barang,
mata_uang,
brand_id,
lini,
harga,
kemasan,
SUM(harga*jumlah_barang) as total_penjualan
FROM
penjualan_update_ds
GROUP BY
id_distributor,
id_cabang,
id_invoice,
tanggal,
id_customer,
id_barang,
jumlah_barang,
mata_uang,
brand_id,
lini,
harga,
kemasan;
# export csv sbg penjualan_update_fix_ds
#penjualan berdasarkan bulan
UPDATE penjualan_update_ds
SET tanggal = STR_TO_DATE(tanggal, '%d/%m/%Y');
SELECT
DATE_FORMAT(tanggal, '%M') AS bulan,
SUM(jumlah_barang) AS total_unit_terjual,
SUM(total_penjualan) AS total_penjualan
FROM
penjualan_update_fix_ds
GROUP BY
DATE_FORMAT(tanggal, '%M');
#Jumlah Barang terjual berdasarkan barang
SELECT
J.id_barang,
P.nama_barang,
SUM(J.jumlah_barang) AS total_barang
FROM
penjualan_update_fix_ds J
INNER JOIN
produk P ON J.id_barang = P.kode_barang
GROUP BY
J.id_barang, P.nama_barang;
#Rata rata penjualan masing-masing lini
SELECT
lini,
AVG(total_penjualan) AS rata_rata_penjualan
FROM
penjualan_update_fix_ds
GROUP BY
lini;
#Penjualan berdasarkan wilayah
SELECT
C.cabang_sales,
SUM(total_penjualan) as total_penjualan,
AVG(total_penjualan) as rata_rata_penjualan
FROM
penjualan_update_fix_ds J
INNER JOIN
customer C on J.id_customer = C.id_customer
GROUP BY
C.cabang_sales;
#Apotek vs Klinik
SELECT
C.group,
SUM(J.jumlah_barang) as total_jumlah_barang,
AVG(J.jumlah_barang * J.harga) as rata_rata_penjualan
FROM
penjualan_update_ds J
INNER JOIN
customer C on J.id_customer = C.id_customer
GROUP BY
C.group;
#total penjualan per barang
SELECT
J.id_barang,
P.nama_barang,
SUM(J.total_penjualan) as total_penjualan,
SUM(J.jumlah_barang) as Total_unit
FROM
penjualan_update_fix_ds J
INNER JOIN
produk P ON J.id_barang = P.kode_barang
GROUP BY
P.nama_barang,
J.id_barang;
SELECT
id_invoice,
J.id_barang,
P.nama_barang,
J.harga,
J.jumlah_barang,
SUM(J.total_penjualan) as total_penjualan
FROM
penjualan_update_fix_ds J
INNER JOIN
produk P ON J.id_barang = P.kode_barang
GROUP BY
id_invoice,
P.nama_barang,
J.harga,
J.jumlah_barang,
J.id_barang;