[HackerRank MySQL] Draw The Triangle 1 & 2 - information_schema.tables
2021. 1. 5. 23:22ㆍToday I Learned.../MySQL
Draw The Triangle 1
P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):
* * * * *
* * * *
* * *
* *
*
Write a query to print the pattern P(20).
set @star = 21;
select repeat('* ', @star := @star -1)
from information_schema.tables
limit 20
Draw The Triangle 2
P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):
*
* *
* * *
* * * *
* * * * *
Write a query to print the pattern P(20).
set @n = 0;
select repeat('* ', @n := @n + 1)
from information_schema.tables
limit 20
INFORMATION_SCHEMA.TABLES?
SQL에서 기본으로 제공하는 테이블로, 이번 문제에서는 테이블의 데이터를 직접 사용하지는 않는다.
하지만 SQL이 동작하기 위해서는 기본적으로 테이블이 필요하므로, 이 테이블을 활용하여 SQL을 작동시킬 수 있다.
The INFORMATION_SCHEMA.TABLES is a built-in tables coming with SQL.
In these problems above, the actual values of INFORMATION_SCHEMA.TABLES is not required, but for running the SQL query it has to refer to a table. The INFORMATION_SCHEMA.TABLES can function as a tool for it.
문제 출처: 해커랭크
'Today I Learned... > MySQL' 카테고리의 다른 글
[LeetCode MySQL] 1179. Reformat Department Table (0) | 2021.01.11 |
---|---|
[HackerRank MySQL] Type of Triangle (0) | 2021.01.11 |
[HackerRank MySQL] INNER JOIN 문제풀기 (Basic) (0) | 2021.01.05 |
[HackerRank MySQL] Weather Observation Station 2, 13-17 - ROUND & TRUNCATE (Basic) (0) | 2021.01.05 |
[HackerRank MySQL] Count/Sum/Average, Ceil/Floor, Replace 문제풀기 (Basic) (0) | 2021.01.05 |