-
Notifications
You must be signed in to change notification settings - Fork 53
/
02. The PADS.sql
37 lines (29 loc) · 1.08 KB
/
02. The PADS.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
-- # Problem: https://www.hackerrank.com/challenges/the-pads/problem
-- # Score: 30
-- # Difficulty: Medium
select
concat(name,"(",upper(substr(occupation,1,1)),")")
from
occupations
order by
name;
select
"There are a total of ",
concat(count(*)," ",lower(occupation),"s.")
from
occupations
group by
occupation
order by
count(*),
occupation;
/* NOTE:
- The CONCAT() function adds two or more expressions together.
- The UPPER() function converts a string to upper-case.
- The LOWER() function converts a string to lower-case.
- The SUBSTR(str,a,b) function extract a substring from a string 'str' starting from position 'a' and extract 'b' number of characters.
- 'ORDER BY A' sort the result in ascending order of A.
- 'ORDER BY A, B' sort the result in ascending order of A, but for the same values of A, it will sort those values in ascending order of B.
- The COUNT(*) function counts the number of rows produced by the query.
- The GROUP BY statement groups rows that have the same values into summary rows.
*/