목록mysql (42)
개발은 처음이라 개발새발
https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ Employees Earning More Than Their Managers - LeetCode Can you solve this real interview question? Employees Earning More Than Their Managers - Table: Employee +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | | salary | int | | managerId | int | +------ l..
https://leetcode.com/problems/customers-who-never-order/description/ Customers Who Never Order - LeetCode Can you solve this real interview question? Customers Who Never Order - Table: Customers +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | +-------------+---------+ id is the primary key column for t leetcode.com 오늘은 JOIN 함수 두번째 퀴즈이자 L..
https://www.hackerrank.com/challenges/average-population-of-each-continent/problem?h_r=internal-search Average Population of Each Continent | HackerRank Query the names of all continents and their respective city populations, rounded down to the nearest integer. www.hackerrank.com 오늘은 JOIN과 관련된 해커랭크의 퀴즈를 들고왔습니다. 문제는 city, country라는 두개의 테이블이 있고 두 테이블을 조인 시켜 country 테이블에 있는 continent를 기준으로 city 테이..
이번에도 CASE문 퀴즈를 풀어보려고 합니다. 이번에는 해커랭크가 아니라 리트코드의 퀴즈를 풀어볼 겁니다. https://leetcode.com/problems/reformat-department-table/ Reformat Department Table - LeetCode Can you solve this real interview question? Reformat Department Table - Table: Department +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | revenue | int | | month | varchar | +-------------+---------+ (i..
https://www.hackerrank.com/challenges/what-type-of-triangle/problem?h_r=internal-search Type of Triangle | HackerRank Query a triangle's type based on its side lengths. www.hackerrank.com 오늘은 삼각형 종류를 지정하는 쿼리로 CASE문 연습을 해보겠습니다. 문제를 보면 A,B,C라는 정수를 담은 컬럼이 있고 이 세 컬럼의 숫자들에 조건을 달아 삼각형의 종류를 지정해보라는 퀴즈입니다. ** 삼각형 종류 Equilateral(정삼각형): It's a triangle with sides of equal length. Isosceles(이등변삼각형): It's a ..
https://www.hackerrank.com/challenges/earnings-of-employees/problem?h_r=internal-search Top Earners | HackerRank Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount). www.hackerrank.com 이번에는 group by와 관련된 간단한 퀴즈를 풀어보겠습니다. 문제를 해석해보면 months와 salary를 곱해 earings라는 컬럼을 만들고 가장 높은 earings과 해당 earings를 기록한 사람이 몇명인지를 카운트해보라는 것을..
집계함수와 관련해 몇가지 문제를 풀어보고자 합니다. 이번에 SQL을 공부하면서 문제를 풀어볼 수 있는 사이트를 알게 됐는데요. 바로 해커랭크입니다. https://www.hackerrank.com/challenges/challenges/problem Challenges | HackerRank Print the total number of challenges created by hackers. www.hackerrank.com EX) 평균 퀴즈 링크 - https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem?h_r=internal-search 예를 들어서 이런 문제들이 있는데요. 문제를 읽어보니 city..
가끔 급하게 데이터를 뽑아서 보게 되면 SQL에서 연산을 하게 되는데요. 그 중에서 소수점을 처리하는 방식을 간단하게 소개해보겠습니다. 1. 올림 올림은 CEIL() 함수를 사용합니다. SELECT CEIL(5.5) => 6 2. 내림 내림은 FLOOR() 함수를 사용합니다. SELECT FLOOR(5.5) => 5 3. 반올림 반올림은 ROUND() 함수를 사용하는데요. ROUND의 경우 ROUND(1.xxxxx, 반올림해서 볼 숫자의 자릿 수)로 입력을 하면됩니다. SELECT CEIL(5.566901,3) => 5.567 간단하게 소수점을 처리하는 방식을 알아봤는데요. 엑셀이나, 파이썬에서도 연산 처리 함수는 거의 동일하기 때문에 알아둔다면 여러 언어에서 사용하기 수월할 것입니다.
MySQL은 기본적으로 SELECT 구문을 활용해 데이터베이스에서 데이터를 그대로 가져오는 것도 있지만 함수를 사용해 해당 컬럼의 갯수를 세어 본다거나 더하기를 하고 평균을 내며 최소/ 최대값 역시 불러올 수 있다. 오늘 예제는 w3schools를 활용해보겠다. w3schools 예제 문제 풀이뿐만 아니라 기본적인 쿼리 연습에 도움이 많이 되는 사이트니 참고하면 좋을 거 같다. https://www.w3schools.com/sql/trysql.asp?filename=trysql_asc SQL Tryit Editor v1.6 WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object. We..
오늘은 실제 업무를 하면서 SQL를 활용할 때 가장 많이 사용하는 구문을 하나 포스팅 해보겠습니다. 저는 실제 스포츠 데이터를 기반으로 분석을 통해 가공 스탯을 만드는 일을 주로 하기 때문에 SQL에서도 연산과 조건문을 자주 사용하는데요. 그중에서 조건문으로 많이 활용하는 CASE...WHEN...THEN입니다. 형식은 아래와 같습니다. CASE WHEN 조건1 THEN 결과값1 WHEN 조건2 THEN 결과값2 WHEN 조건3 THEN 결과값3 ELSE 결과값 END 형식을 보면 알다시피 WHEN과 THEN은 항상 같이 사용됩니다. 그리고 WHEN과 THEN은 여러개를 사용할 수 있습니다. ELSE의 경우는 WHEN ...THEN...의 조건문에 모두 부합되지 않을 때 표출될 값입니다. 파이썬의 조건문..