1. [MySQL] 경기결과 승점 계산

    테이블과 결과

    Input: 
    Teams table:
    +-----------+--------------+
    | team_id   | team_name    |
    +-----------+--------------+
    | 10        | Leetcode FC  |
    | 20        | NewYork FC   |
    | 30        | Atlanta FC   |
    | 40        | Chicago FC   |
    | 50        | Toronto FC   |
    +-----------+--------------+
    Matches table:
    +------------+--------------+---------------+-------------+--------------+
    | match_id   | host_team    | guest_team    | host_goals  | guest_goals  |
    +------------+--------------+---------------+-------------+--------------+
    | 1          | 10           | 20            | 3           | 0            |
    | 2          | 30           | 10            | 2           | 2            |
    | 3          | 10           | 50            | 5           | 1            |
    | 4          | 20 …
    read more
  2. [MySQL] 한 줄로 출력

    테이블과 결과

    Input: 
    Activities table:
    +------------+------------+
    | sell_date  | product     |
    +------------+------------+
    | 2020-05-30 | Headphone  |
    | 2020-06-01 | Pencil     |
    | 2020-06-02 | Mask       |
    | 2020-05-30 | Basketball |
    | 2020-06-01 | Bible      |
    | 2020-06-02 | Mask       |
    | 2020-05-30 | T-Shirt    |
    +------------+------------+
    Output: 
    +------------+----------+------------------------------+
    | sell_date  | num_sold | products                     |
    +------------+----------+------------------------------+
    | 2020-05-30 | 3        | Basketball,Headphone …
    read more
  3. [MySQL] 하루 단위로 7일 동안의 매출 평균

    테이블과 결과

    Input: 
    Customer table:
    +-------------+--------------+--------------+-------------+
    | customer_id | name         | visited_on   | amount      |
    +-------------+--------------+--------------+-------------+
    | 1           | Jhon         | 2019-01-01   | 100         |
    | 2           | Daniel       | 2019-01-02   | 110         |
    | 3           | Jade         | 2019-01-03   | 120         |
    | 4           | Khaled       | 2019-01-04   | 130         |
    | 5           | Winston      | 2019-01-05   | 110         | 
    | 6           | Elvis        | 2019-01-06   | 140         | 
    | 7 …
    read more
  4. [MySQL] INDEX

    Index

    • 추가적인 쓰기 작업과 저장 공간을 활용하여 데이터베이스 테이블의 검색 속도를 향상 시키기 위한 자료구조

    용어

    • 테이블 …
    read more
  5. [MySQL] JOIN

    가장 rows가 많은 테이블을 먼저 배치해라(쿼리 옵티마이저)

    INNER JOIN

    • 원래 아는 그거

    OUTER JOIN

    SELF JOIN

    SELECT p.name AS parent, c.name AS child
    FROM tree c, tree p
    WHERE …
    read more
  6. [MySQL] JOIN ON 조건 >=

    테이블과 결과

    Input: 
    Buses table:
    +--------+--------------+
    | bus_id | arrival_time |
    +--------+--------------+
    | 1      | 2            |
    | 2      | 4            |
    | 3      | 7            |
    +--------+--------------+
    Passengers table:
    +--------------+--------------+
    | passenger_id | arrival_time |
    +--------------+--------------+
    | 11           | 1            |
    | 12           | 5            |
    | 13           | 6            |
    | 14           | 7            |
    +--------------+--------------+
    Output: 
    +--------+----------------+
    | bus_id | passengers_cnt |
    +--------+----------------+
    | 1      | 1              |
    | 2      | 0              |
    | 3      | 3              |
    +--------+----------------+
    Explanation: 
    - Passenger 11 arrives at time 1.
    - Bus 1 arrives at time …
    read more
  7. [MySQL] JOIN ON 조건 IN()

    테이블과 결과

    Input: 
    Person table:
    +----+----------+--------------+
    | id | name     | phone_number |
    +----+----------+--------------+
    | 3  | Jonathan | 051-1234567  |
    | 12 | Elvis    | 051-7654321  |
    | 1  | Moncef   | 212-1234567  |
    | 2  | Maroua   | 212-6523651  |
    | 7  | Meir     | 972-1234567  |
    | 9  | Rachel   | 972-0011100  |
    +----+----------+--------------+
    Country table:
    +----------+--------------+
    | name     | country_code |
    +----------+--------------+
    | Peru     | 051          |
    | Israel   | 972          |
    | Morocco  | 212          |
    | Germany  | 049          |
    | Ethiopia | 251 …
    read more
  8. [MySQL] 중복제거 카운트

    테이블과 결과

    Input: 
    Activity table:
    +---------+------------+---------------+---------------+
    | user_id | session_id | activity_date | activity_type |
    +---------+------------+---------------+---------------+
    | 1       | 1          | 2019-07-20    | open_session  |
    | 1       | 1          | 2019-07-20    | scroll_down   |
    | 1       | 1          | 2019-07-20    | end_session   |
    | 2       | 4          | 2019-07-20    | open_session  |
    | 2       | 4          | 2019-07-21    | send_message  |
    | 2       | 4          | 2019-07-21    | end_session   |
    | 3 …
    read more

links

social