1. [MySQL] 평균 구하기

    테이블과 결과

    Input: 
    Signups table:
    +---------+---------------------+
    | user_id | time_stamp          |
    +---------+---------------------+
    | 3       | 2020-03-21 10:16:13 |
    | 7       | 2020-01-04 13:57:59 |
    | 2       | 2020-07-29 23:09:44 |
    | 6       | 2020-12-09 10:39:37 |
    +---------+---------------------+
    Confirmations table:
    +---------+---------------------+-----------+
    | user_id | time_stamp          | action    |
    +---------+---------------------+-----------+
    | 3       | 2021-01-06 03:30 …
    read more
  2. [MySQL] REGEXP_LIKE

    테이블과 결과

    Input: 
    Patients table:
    +------------+--------------+--------------+
    | patient_id | patient_name | conditions   |
    +------------+--------------+--------------+
    | 1          | Daniel       | YFEV COUGH   |
    | 2          | Alice        |              |
    | 3          | Bob          | DIAB100 MYOP |
    | 4          | George       | ACNE DIAB100 |
    | 5          | Alain        | DIAB201      |
    +------------+--------------+--------------+
    Output: 
    +------------+--------------+--------------+
    | patient_id | patient_name | conditions   |
    +------------+--------------+--------------+
    | 3          | Bob          | DIAB100 MYOP |
    | 4          | George       | ACNE DIAB100 | 
    +------------+--------------+--------------+
    Explanation: Bob and George both have a condition that …
    read more
  3. [MySQL] SELECT 존재여부 체크

    SELECT 존재여부 체크

    • COUNT(*)로 세는 것이 더 느릴 수 있다. 그냥 1로 해라
    SELECT EXISTS 
    (
        SELECT 1
        FROM CVVE_POINT.CPO_POINT_EARN cpe, CVVE_CUSTOMER.CR_CUSTOMER cc
        WHERE cpe.CR_ID = cc.CR_ID
        AND cpe.CUH_ID = cc.CUH_ID
        AND cpe.CPE_ISSUE_DT BETWEEN DATE_ADD …
    read more
  4. [MySQL] SELF JOIN

    테이블

    Employee 테이블

    id name salary managerId
    1 Joe 70000 3
    2 Henry 80000 4
    3 Sam 60000
    4 Max 90000

    문제

    • 자신의 매니저보다 많이 salary를 받는 인원을 뽑으시오

    SELECT e1 …
    read more
  5. [MySQL] 실행계획

    실행계획

    • id: select id
    • select_type: SIMPLE, UNION, SUBQUERY, etc
    • type: data scan type (const, ALL, ref, range, index, fulltext, etc)
    • const: 클러스터드 인덱스, 유니크 인덱스를 사용했을 때
    • ALL: 인덱스를 타 …
    read more

links

social