1. [MySQL] FULL OUTER JOIN

    테이블과 결과

    Input: 
    Employees table:
    +-------------+----------+
    | employee_id | name     |
    +-------------+----------+
    | 2           | Crew     |
    | 4           | Haven    |
    | 5           | Kristian |
    +-------------+----------+
    Salaries table:
    +-------------+--------+
    | employee_id | salary |
    +-------------+--------+
    | 5           | 76071  |
    | 1           | 22517  |
    | 4           | 63539  |
    +-------------+--------+
    Output: 
    +-------------+
    | employee_id |
    +-------------+
    | 1           |
    | 2           |
    +-------------+
    Explanation: 
    Employees 1, 2, 4, and 5 are working at this company.
    The name of employee 1 is missing …
    read more
  2. [MySQL] 가장 가까운 좌표(x, y) 구하기

    테이블과 결과

    Input: 
    Point2D table:
    +----+----+
    | x  | y  |
    +----+----+
    | -1 | -1 |
    | 0  | 0  |
    | -1 | -2 |
    +----+----+
    Output: 
    +----------+
    | shortest |
    +----------+
    | 1.00     |
    +----------+
    Explanation: The shortest distance is 1.00 from point (-1, -1) to (-1, 2).
    

    문제

    The distance between two points p1(x1, y1) and p2(x2, y2) is …

    read more
  3. [MySQL] 그룹별 최고 금액 보유자 뽑기

    테이블과 결과

    Input: 
    Employee table:
    +----+-------+--------+--------------+
    | id | name  | salary | departmentId |
    +----+-------+--------+--------------+
    | 1  | Joe   | 70000  | 1            |
    | 2  | Jim   | 90000  | 1            |
    | 3  | Henry | 80000  | 2            |
    | 4  | Sam   | 60000  | 2            |
    | 5  | Max   | 90000  | 1            |
    +----+-------+--------+--------------+
    Department table:
    +----+-------+
    | id | name  |
    +----+-------+
    | 1  | IT    |
    | 2  | Sales |
    +----+-------+
    Output: 
    +------------+----------+--------+
    | Department | Employee | Salary |
    +------------+----------+--------+
    | IT         | Jim      | 90000  |
    | Sales      | Henry …
    read more
  4. [MySQL] 그룹별 랭킹상위 N명 구하기

    테이블과 결과

    Input: 
    Employee table:
    +----+-------+--------+--------------+
    | id | name  | salary | departmentId |
    +----+-------+--------+--------------+
    | 1  | Joe   | 85000  | 1            |
    | 2  | Henry | 80000  | 2            |
    | 3  | Sam   | 60000  | 2            |
    | 4  | Max   | 90000  | 1            |
    | 5  | Janet | 69000  | 1            |
    | 6  | Randy | 85000  | 1            |
    | 7  | Will  | 70000  | 1            |
    +----+-------+--------+--------------+
    Department table:
    +----+-------+
    | id | name  |
    +----+-------+
    | 1  | IT    |
    | 2  | Sales |
    +----+-------+
    Output …
    read more
  5. [MySQL] 그룹별 순서 매기기

    그룹별 순서 매기기

    SELECT 
        pf.*
        ,CASE
            WHEN @grp = pf.painpoint_id
                THEN @rownum:= @rownum + 1
            ELSE @rownum := 1
        END AS feebackOrder
        ,(@grp:= pf.painpoint_id) AS dum
    FROM painpoint_feedback pf, (SELECT @rownum:= 0, @grp:= '') r
    ORDER BY pf.painpoint_id 
    ;
    
    read more
  6. [MySQL] GROUP BY

    GROUP BY 와 HAVING

    설명

    GROUP BY를 사용할 때는 두가지를 기억

    • 특정 컬럼을 그룹화 하는 GROUP BY
    • 특정 컬럼을 그룹화한 결과에 조건을 거는 HAVING

    WHERE과 …

    read more

links

social