Other articles


  1. [MySQL] 1대 다 LEFT JOIN

    테이블과 결과

    Input: 
    Visits
    +----------+-------------+
    | visit_id | customer_id |
    +----------+-------------+
    | 1        | 23          |
    | 2        | 9           |
    | 4        | 30          |
    | 5        | 54          |
    | 6        | 96          |
    | 7        | 54          |
    | 8        | 54          |
    +----------+-------------+
    visit_id is the primary key for this table.
    This table contains information about the customers who visited the mall.
    
    Transactions
    +----------------+----------+--------+
    | transaction_id | visit_id | amount |
    +----------------+----------+--------+
    | 2              | 5        | 310 …
    read more
  2. [MySQL] ALL

    테이블

    orders

    order_number customer_number
    1 1
    2 2
    3 3
    4 3

    문제

    • 가장 주문 횟수가 많은 고객을 뽑으시오

    -- 1위 한 명만
    SELECT o.customer_number
    FROM orders o 
    GROUP BY o.customer_number 
    ORDER BY COUNT …
    read more
  3. [MySQL] CASE

    참고

    MySQL Documentation 13.6.5.1 CASE Statement

    syntax

    CASE case_value
        WHEN when_value THEN statement_list
        [WHEN when_value THEN statement_list] ...
        [ELSE statement_list]
    END CASE
    

    Or:

    CASE
        WHEN search_condition THEN statement_list
        [WHEN search_condition THEN statement_list] ...
        [ELSE statement_list]
    END CASE
    

    주의

    • 만약 매칭되는 WHEN이 없으 …
    read more
  4. [MySQL] 첫 글자만 대문자로

    테이블과 결과

    Input: 
    Users table:
    +---------+-------+
    | user_id | name  |
    +---------+-------+
    | 1       | aLice |
    | 2       | bOB   |
    +---------+-------+
    user_id is the primary key for this table.
    This table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.
    
    Output: 
    +---------+-------+
    | user_id | name  |
    +---------+-------+
    | 1       | Alice |
    | 2       | Bob …
    read more

links

social