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).
information_schema
사용SET @변수명 = 값
*
이 줄어들어야함SET @number = 21;
SELECT REPEAT('* ', @number := @number - 1)
FROM information_schema.tables
LIMIT 20;
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).
풀이
- Draw The Triangle 1와 99% 같은 코드
: 0부터 시작해서, +1 ~ 20까지. 총 20번의*
SET @number = 0; SELECT REPEAT('* ', @number := @number + 1) FROM information_schema.tables LIMIT 20;
Write a query to print all prime numbers less than or equal to . Print your result on a single line, and use the ampersand () character as your separator (instead of a space).
For example, the output for all prime numbers would be:
2&3&5&7
&
넣기SELECT GROUP_CONCAT(NUMB SEPARATOR '&')
FROM (
SELECT @num:=@num+1 as NUMB FROM
information_schema.tables t1,
information_schema.tables t2,
(SELECT @num:=1) tmp
) tempNum
WHERE NUMB<=1000 AND NOT EXISTS(
SELECT * FROM (
SELECT @nu:=@nu+1 as NUMA FROM
information_schema.tables t1,
information_schema.tables t2,
(SELECT @nu:=1) tmp1
LIMIT 1000
) tatata
WHERE FLOOR(NUMB/NUMA)=(NUMB/NUMA) AND NUMA<NUMB AND NUMA>1
);
GROUP_CONCAT
: 구분자 삽입