본문 바로가기

Algorithm/Code Fights (Code Signal)

CodeSignal Intro Databases #5 AutomaticNotifications. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기..

CodeSignal Intro Databases #5 AutomaticNotifications. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, 데이터베이스, sql, query, 쿼리

 

 

CodeSignal Intro Databases #5

Q.

Implement the missing code, denoted by ellipses. You may not modify the pre-existing code.

 말줄임표로 빠져있는 코드를 채워라. 이미 있는 코드는 건드리지 말고.

 

The application you've been working on for the past year is a huge success! It already has a large and active user community. You know the ID number, username, and email of each user. Each user also has a specific role that shows their position in the community. Information about the users is stored in the database as a table users, which has the following structure:

  • id: the unique user ID;
  • username: the username of the user;
  • role the user's role;
  • email: the user's email.

 지난 몇년간 일해온 어플리케이션이 크게 성공했다! 이건 이미 크고 활동적인 유저 커뮤니티이다. 넌 ID number, username, 그리고 email 을 알고 있다. 또한 각 유저는 커뮤니티에서 특정한 역할을 갖고 있다. 유저들에 대한 정보는 users 라는 테이블로 데이터베이스에 저장되어있고 다음과 같다.

  • id: 유니크한 유저 아이디
  • username: 유저의 유저이름
  • role: 유저의 역할
  • email: 유저의 이메일

 You want to send users automatic notifications to let them know about the most recent updates. However, not all users should get these notifications: Administrators don't need notifications since they know about the updates already, and premium users don't need them since they get personalized weekly updates.

Given the users table, your task is to return the emails of all the users who should get notifications, i.e. those whose role is not equal to "admin" or "premium". Note that roles are case insensitive, so users with roles of "Admin", "pReMiUm", etc. should also be excluded.

The resulting table should contain a single email column and be sorted by emails in ascending order.

 

 넌 유저들에게 최신 업데이트를 자동으로 알림이 되길 바란다. 그러나, 모든 유저에게는 아니고, 관리자는 이미 업데이트를 알고 있어서 받을 필요가 없고, 프리미엄 유저는 따로 업데이트를 받기 때문에 필요가 없다.

 users 테이블이 주어지고, 알림을 받아야하는 모든 유저들의 이메일을 리턴해라, 예를들면, admin 이나 premium 유저가 아닌 사람들. 역할들은 대소문자를 구분하지 않아서(case-insensitive), 섞여있는건 제외된다.

결과 테이블은 email 한개의 컬럼이고, email 의 오름차순으로 정렬된다.

 

Example

 

For the following table users

id

username

role

email

6 fasalytch premium much.premium@role.com
13 luckygirl regular fun@meh.com
16 todayhumor guru today@humor.com
23 Felix admin felix@codesignal.com
52 admin666 AdmiN iamtheadmin@admin.admin
87 solver100500 regular email@notbot.com

 

the resulting table should be

 

email

email@notbot.com
fun@meh.com
today@humor.com

 

 The only three users who should get notifications are luckygirl, todayhumor, and solver100500. Their emails are fun@meh.com, today@humor.com, and email@notbot.com respectively, which should be sorted as email@notbot.com, fun@meh.com, and today@humor.com.

  • [execution time limit] 10 seconds (mysql)

 

Process

// Process 
//1. SELECT email column

//2. In users table

//3. role column value is not admin AND not premium (NOT IN ("admin", "premium"))

//4. ORDER BY emain in an ascending way

 

 

// 처리과정

//1. email 컬럼을 SELECT 하는데,

//2. users 테이블에서,

//3. role 컬럼의 값이 admin 아니고 AND premium 아닌 것

//4. email 의 오름차순으로 정렬하여 보여준다.

 

 

Code.. lemme see example code!!!

코드.. 예제코드를 보자!!!

 

 

CREATE PROCEDURE automaticNotifications()
    SELECT email
    FROM users
    WHERE role NOT IN ("admin", "premium")

    ORDER BY email;

 

 

 

Something else you might like...?

 

2019/10/23 - [Algorithm/Code Fights (Code Signal)] - CodeSignal Intro Databases #1 ProjectList. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접, ..

2019/10/20 - [Algorithm/Leet Code] - LeetCode #181 EmployeesEarningMoreTheirManagers. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면..

 

 

2019/09/04 - [Programming/C++] - How to sort vector in C++, 벡터 정렬하는 방법,sorting,배열,stl,씨쁠쁠,example code,예제코드,표준라이브러리

 

 

2019/10/09 - [Computer/General] - 정보처리기사 실기/필기 - IT신기술동향_전산영어 요점 정리

2019/10/07 - [Computer/General] - 정보처리기사 실기/필기 - 업무 프로세스 요점 정리

 

 

2019/08/14 - [Life/Item review] - Mi Band 4 review, 미밴드4 후기, 장점, 단점, 리뷰, 한글, global review, 미밴드4 글로벌 후기, 리뷰, 구매, 사용방법, setting, 세팅, ProsNCons

 

 

2019/08/27 - [Programming] - 개발자 선배들에게서 배운 것들. Things I Learnt from a Senior Software Engineer. 코딩 잘하는 방법, how to code well, 소프트웨어,프로그래머,programmer

 

 

2019/04/14 - [Programming/C++] - C++ Math - sqrt (square root, 제곱근, 루트). stl, math.h, 씨쁠쁠, example code, 예제코드

 

 

2018/10/19 - [Programming/Design Pattern ] - Design pattern - Prototype (디자인패턴 - 프로토타입) / Java C++ C#

 

 

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

2019/01/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #58 messageFromBinaryCode. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive

 

 

2019/09/17 - [Algorithm/Leet Code] - LeetCode #841 KeysAndRooms. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,그래프,Graph,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접

2019/08/28 - [Algorithm/Leet Code] - LeetCode #821 ShortestDistanceToACharacter. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접..

 

 

2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)

2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)

 

 

2019/01/14 - [Programming/Java] - 자바 메모리 누수 체크/확인/고치는 방법, Memory leak check/fix in Java application, cleanCode/좋은코드/oop/객체지향

 

 

2019/02/19 - [Life/Health care] - Lysine 라이신 usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/16 - [Life/Health care] - Finasteride 피나스테라이드,탈모약 usage/side effects/dosage 효능/부작용/효과/sexual effect/두타스테라이드/프로페시아/propecia/finpecia/카피약/copy drug/hair loss

2019/02/25 - [Life/Health care] - Folic Acid 엽산 vitaminB9,비타민M usage/side effects/dosage 효과/효능/부작용/성인,소아 용법, 복용법

2019/02/28 - [Life/Health care] - Vitamin K, 비타민 K usage/side effects/dosage 효능/부작용/성인,소아 용법

2019/03/03 - [Life/Health care] - Vitamin B1, Thiamine, 비타민 B1, 티아민 usage/side effects/dosage 효능/부작용/성인,소아 용법