Skip to content

Commit 74cf390

Browse files
authored
Update Cahllenge 1 Steve's car showroom.md
1 parent 7d03686 commit 74cf390

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

Cahllenge 1 Steve's car showroom.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,68 @@ VALUES (1, 1, 1, '2021-01-01'),
8181
## Ad-Hoc Questions and Solutions
8282
### 1. What are the details of all cars purchased in the year 2022?
8383

84-
``` SQL code ```
84+
``` SQL
85+
SELECT *
86+
FROM cars
87+
WHERE car_id IN (
88+
SELECT car_id
89+
FROM sales2
90+
WHERE YEAR(purchase_date) = 2022
91+
);
92+
```
8593

8694
### 2. What is the total number of cars sold by each salesperson?
87-
``` SQL code ```
95+
``` SQL
96+
SELECT s.name AS Salesperson,
97+
COUNT(*) AS Total_Cars_Sold
98+
FROM salespersons s
99+
JOIN sales2 sa ON s.salesman_id = sa.salesman_id
100+
GROUP BY s.name;
101+
```
88102

89103
### 3.What is the total revenue generated by each salesperson?
90104

91-
``` SQL code ```
105+
``` SQL
106+
SELECT s.name AS Salesperson,
107+
SUM(c.cost_$) AS Total_Revenue_Generated
108+
FROM salespersons s
109+
JOIN sales2 sa ON s.salesman_id = sa.salesman_id
110+
JOIN cars c ON sa.car_id = c.car_id
111+
GROUP BY s.name;
112+
```
92113

93114
### 4. What are the details of the cars sold by each salesperson?
94115

95-
``` SQL code ```
116+
``` SQL
117+
SELECT s.name AS Salesperson,
118+
c.*
119+
FROM salespersons s
120+
JOIN sales2 sa ON s.salesman_id = sa.salesman_id
121+
JOIN cars c ON sa.car_id = c.car_id;
122+
```
96123
### 5. What is the total revenue generated by each car type?
97124

98-
``` SQL code ```
125+
``` SQL
126+
SELECT c.type,
127+
SUM(c.cost_$) AS Total_Revenue_Generated
128+
FROM cars c
129+
JOIN sales2 sa ON c.car_id = sa.car_id
130+
GROUP BY c.type;
131+
```
99132
### 6. What are the details of the cars sold in the year 2021 by salesperson 'Emily Wong'?
100133

101-
``` SQL code ```
134+
``` SQL
135+
SELECT c.*
136+
FROM cars c
137+
JOIN sales2 sa ON c.car_id = sa.car_id
138+
JOIN salespersons s ON sa.salesman_id = s.salesman_id
139+
WHERE YEAR(sa.purchase_date) = 2021 AND s.name = 'Emily Wong';
140+
```
141+
# car_id, make, type, style, cost_$
142+
2, Toyota, Corolla, Hatchback, 25000
143+
4, Chevrolet, Camaro, Coupe, 36000```
144+
145+
```
102146
### 7. What is the total revenue generated by the sales of hatchback cars?
103147
104148
``` SQL code ```

0 commit comments

Comments
 (0)