-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.sql
79 lines (70 loc) · 3.58 KB
/
queries.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
/* Average, minimum and maximum guitar price */
select avg(price) avg_price, min(price) min_price, max(price) max_price
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
/* Avg guitar price, avg guitar_score and total guitar count by each brand. */
select gf.brand, count(*) as guitar_count, round(avg(eg.price),2) as avg_price,
round(avg(eg.guitar_score),2) as avg_score
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_info gf on eg.info_id = gf.info_id
group by gf.brand
order by avg_price desc;
/* Average price for origin of the guitar */
select gf.made_in, round(avg(eg.price),2) as avg_price
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_info gf on eg.info_id = gf.info_id
group by gf.made_in
order by avg_price desc
/* Top 10 most used body woods */
select body_material, wood_count
from (
select gb.body_material,
row_number() over(order by count(*) desc) as rank,
count(*) as wood_count
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_body gb
on eg.body_id = gb.body_id
group by gb.body_material
) where rank <= 10;
/* Avg price for pickup and wood quality */
select has_top_brand_pickups, has_expensive_wood, avg(price) as avg_price
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_strengths_and_weaknesses stwk
on eg.st_and_wk_id = stwk.st_and_wk_id
group by has_top_brand_pickups, has_expensive_wood
/* Neck joint and guitar price */
select neck_joint, round(avg(eg.price),2) as avg_price
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_neck gn
on eg.neck_id = gn.neck_id
group by neck_joint
/* Most 5 common used neck shapes */
select shape, shape_count
from (
select shape, row_number() over(order by count(*) desc) as rank,
count(*) as shape_count
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_neck gn
on eg.neck_id = gn.neck_id
group by shape
) where rank <= 5;
/* Build a table to use in data analytics */
create or replace table steady-copilot-413818.electric_guitars_dataset.table_analytics as (
select model_name, price, guitar_score, guitar_color, body_material, bridge, body_type,
pickup_configuration, switch, volume_controls, tone_controls, fretboard_material,
frets, fret_number, fretboard_radius, brand, series, year, made_in, strings,
neck_joint, neck_material, scale_size, shape, nut, nut_width, has_locking_tuners,
has_tremolo, has_top_brand_pickups, has_expensive_wood, has_neck_through_build,
has_high_quality_nut
from steady-copilot-413818.electric_guitars_dataset.electric_guitars eg
join steady-copilot-413818.electric_guitars_dataset.guitar_body gb
on eg.body_id = gb.body_id
join steady-copilot-413818.electric_guitars_dataset.guitar_electronics ge
on eg.electronics_id = ge.electronics_id
join steady-copilot-413818.electric_guitars_dataset.guitar_fretboard gf
on gf.fretboard_id = eg.fretboard_id
join steady-copilot-413818.electric_guitars_dataset.guitar_info gi
on gi.info_id = eg.info_id
join steady-copilot-413818.electric_guitars_dataset.guitar_neck gn
on eg.neck_id = gn.neck_id
join electric_guitars_dataset.guitar_strengths_and_weaknesses stwk
on stwk.st_and_wk_id = eg.st_and_wk_id );