Skip to content

Commit 1f9ab18

Browse files
committed
2 parents 2e8a617 + 6efd9d0 commit 1f9ab18

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

Diff for: 7kyu/SQL-Padding-Encryption.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
You are given a table with the following format:
3+
4+
**encryption table schema**
5+
6+
- md5
7+
- sha1
8+
- sha256
9+
10+
Problem is the table looks so unbalanced - the sha256 column contains much longer strings. You need to balance things up. Add '1' to the end of the md5 addresses as many times as you need to to make them the same length as those in the sha256 column. Add '0' to the beginning of the sha1 values to achieve the same result.
11+
12+
Return as:
13+
14+
**output table schema**
15+
16+
- md5
17+
- sha1
18+
- sha256
19+
20+
```sql
21+
/* SQL */
22+
SELECT CONCAT(md5, REPEAT('1', LENGTH(sha256) - LENGTH(md5))) as md5, CONCAT(REPEAT('0', LENGTH(sha256)- LENGTH(sha1)), sha1) as sha1, sha256
23+
FROM encryption;
24+
```

Diff for: 7kyu/SQL-Right-and-Left.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
You are given a table named repositories, format as below:
2+
3+
**repositories table schema**
4+
5+
- project
6+
- commits
7+
- contributors
8+
- address
9+
10+
The table shows project names of major cryptocurrencies, their numbers of commits and contributors and also a random donation address ( not linked in any way :) ).
11+
12+
For each row: Return first x characters of the project name where x = commits. Return last y characters of each address where y = contributors.
13+
14+
Return project and address columns only, as follows:
15+
16+
**output table schema**
17+
18+
- project
19+
- address
20+
21+
Case should be maintained.
22+
23+
```sql
24+
/* SQL */
25+
SELECT substring(project,0, commits+1) as project, substring(address,(LENGTH(address)-contributors)+1, LENGTH(address)) as address FROM repositories
26+
```
27+
28+
OR
29+
30+
```sql
31+
/* SQL */
32+
SELECT LEFT(project, commits) as project, RIGHT(address, contributors) as address FROM repositories;
33+
```

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
|8 kyu|Easy SQL: LowerCase|[link](/8kyu/Easy-SQL-LowerCase.md)|`LOWER`|
4747
|7 kyu|SQL: Concatenating Columns|[link](/7kyu/SQL-Concatenating-Columns.md)|`CONCAT`|
4848
|7 kyu|SQL Basics - Trimming the Field|[link](/7kyu/SQL-Basics-Trimming-the-Field.md)|`split_part`|
49+
|7 kyu|SQL: Right and Left|[link](/7kyu/SQL-Right-and-Left.md)|`LEFT``RIGHT``substring`|
50+
|7 kyu|SQL: Padding Encryption|[link](/7kyu/SQL-Padding-Encryption.md)|`REPEAT``CONCAT`|
4951

5052
## 聚合
5153
|難度|題目|答案|使用的函數|

0 commit comments

Comments
 (0)