forked from musa-5090-spring-2024/assignment01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query02.sql
34 lines (24 loc) · 1.01 KB
/
query02.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
/*
What is the percent change in trips in Q3 2022 as compared to Q3 2021?
Using only the tables from Q3 2021 and Q3 2022 (i.e. not directly using the
number calculated in the previous question), find the percent change in the
number of trips in Q3 2022 as compared to 2021. Round your answer to two
decimal places and name the resulting field `perc_change`.
Remember you can do calculations in the select clause.
*/
-- Enter your SQL query here
select
round(
100 * (
(select count(*) from indego.trips_2022_q3) -
(select count(*) from indego.trips_2021_q3)
) ::numeric /
(select count(*) from indego.trips_2021_q3), 2)
::text || '%' AS perc_change
/*
If you want to get fancier here, you can cast the result to a string and
concatenate a '%' to the end. For example:
(10 + 3.2)::text || '%' AS perc_change
This uses the type casting (number to string) and string concatenation
operator (`||`, double pipes) that's essentially a `+` for strings.
*/