이 영역을 누르면 첫 페이지로 이동
쿄코코 블로그의 첫 페이지로 이동

쿄코코

페이지 맨 위로 올라가기

쿄코코

얼레벌레 생활🤯

Draw The Triangle 1,Draw The Triangle 2,Print Prime Numbers

  • 2022.12.20 19:24
  • SQL/HackerRank
    반응형

     

    Draw The Triangle 1 📝 

    https://www.hackerrank.com/challenges/draw-the-triangle-1/problem?isFullScreen=true 

    • information.table : 데이터베이스에 존재하는 테이블에 대한 정보 제공.

    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 @number = 21; -- number 21로 지정
    select repeat('* ', @number := @number - 1) 
    from information_schema.tables;

     


     

    Draw The Triangle 2 📝 

    https://www.hackerrank.com/challenges/draw-the-triangle-2/problem?isFullScreen=true 

    • information.table : 데이터베이스에 존재하는 테이블에 대한 정보 제공.
    • 어....초면인 설명인데 할말이 없는 설명이다...⭐️

    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 @number = 0;
    select repeat('* ', @number := @number + 1) 
    from information_schema.tables
    LIMIT 20;

     


     

    Print Prime Numbers 📝 

    https://www.hackerrank.com/challenges/print-prime-numbers/problem?isFullScreen=true 

    • 1 . 2부터 1000까지 채우기(1은 어차피 소수가 아니므로 제외)
    • 2부터 차례대로 나누었을 때 나누어지는 값 제외시키기( 본인 값은 제외 num != k )
    • 출력 시 &로 이어서 붙이기

    Write a query to print all prime numbers less than or equal to 1000. 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

     

    CREATE TABLE nonprimenumber(num INT PRIMARY KEY); --빈테이블 만들기
    
    -- 2부터 1000까지 채우기
    DELIMITER $$ 
    CREATE PROCEDURE fill1000()
    BEGIN
        DECLARE i INT DEFAULT 2; 
        WHILE (i <= 1000) DO
            INSERT INTO nonprimenumber VALUE (i); 
            SET i = i + 1; 
        END WHILE;
    END$$
    DELIMITER ;
    
    
    DELIMITER $$
    CREATE PROCEDURE loop_test()
    BEGIN 
        DECLARE k INT DEFAULT 2;
        WHILE(k <= 1000) DO  
            DELETE FROM nonprimenumber WHERE num%k = 0 AND num!=k ;
            SET k = k+1 ;
        END WHILE;
    END$$
    DELIMITER ;
    
    CALL fill1000();
    CALL loop_test();
    SELECT GROUP_CONCAT(num separator '&') FROM nonprimenumber;
    반응형

    'SQL > HackerRank' 카테고리의 다른 글

    Interviews,15 Days of Learning SQL  (0) 2022.12.27
    SQL Project Planning,Placements,Symmetric Pairs  (0) 2022.12.06
    Ollivander's Inventory, Challenges,Contest Leaderboard  (0) 2022.11.22
    African Cities, The Report, Top Competitors  (0) 2022.11.15
    African Cities, Average Population of Each Continent, Weather Observation Station 5, Binary Tree Nodes, New Companies  (0) 2022.10.31

    댓글

    이 글 공유하기

    • 구독하기

      구독하기

    • 카카오톡

      카카오톡

    • 라인

      라인

    • 트위터

      트위터

    • Facebook

      Facebook

    • 카카오스토리

      카카오스토리

    • 밴드

      밴드

    • 네이버 블로그

      네이버 블로그

    • Pocket

      Pocket

    • Evernote

      Evernote

    다른 글

    • Interviews,15 Days of Learning SQL

      Interviews,15 Days of Learning SQL

      2022.12.27
    • SQL Project Planning,Placements,Symmetric Pairs

      SQL Project Planning,Placements,Symmetric Pairs

      2022.12.06
    • Ollivander's Inventory, Challenges,Contest Leaderboard

      Ollivander's Inventory, Challenges,Contest Leaderboard

      2022.11.22
    • African Cities, The Report, Top Competitors

      African Cities, The Report, Top Competitors

      2022.11.15
    다른 글 더 둘러보기

    정보

    쿄코코 블로그의 첫 페이지로 이동

    쿄코코

    • 쿄코코의 첫 페이지로 이동

    검색

    메뉴

    • 홈

    카테고리

    • 분류 전체보기 (172)
      • Python (24)
        • 😈 99클럽 코테 스터디 4기 TIL (23)
        • 궁금한거 정리 (1)
      • SQL (16)
        • HackerRank (15)
      • [백준] Python,Java로 풀기📖 (71)
        • 정렬(Sorting) (6)
        • 그리디 (5)
        • 문자열 (7)
        • 수학 (3)
        • DFS&BFS (10)
        • 구현 (4)
        • 다이나믹 (17)
        • 이분탐색 (1)
        • 자료구조 (10)
        • 최단거리 (5)
        • 인덱스트리 (0)
      • [프로그래머스]Python,Java로 풀기 (6)
        • Level 1 (4)
        • Level 2 (2)
      • Study Platform📚 (28)
        • 김영한👨🏻‍🏫의 스프링 부트와 JPA 실무 완전 .. (5)
        • (알고리즘)- [이코테] 이것이 코딩테스트다 정리 (10)
        • 그림으로 배우는 Http&Network Basic (10)
        • AWS SAA C03공부하기 (3)
      • 까먹을까봐 적는 것들 (5)
      • 테스트 보고 난 후..🤔 (0)
      • kt 에이블스쿨 (18)

    최근 글

    인기 글

    댓글

    공지사항

    아카이브

    태그

    • 99클럽
    • 오블완
    • 백준
    • 티스토리챌린지
    • TiL
    • 항해99
    • 코딩테스트준비
    • 프로그래머스

    나의 외부 링크

    정보

    쿄코코의 쿄코코

    쿄코코

    쿄코코

    블로그 구독하기

    • 구독하기
    • RSS 피드

    방문자

    • 전체 방문자
    • 오늘
    • 어제

    티스토리

    • 티스토리 홈
    • 이 블로그 관리하기
    • 글쓰기
    Powered by Tistory / Kakao. © 쿄코코. Designed by Fraccino.

    티스토리툴바