πν
μ΄λΈ μ¬μ΄μ 볡μ‘ν κ΄κ³λ₯Ό νμ
ν΄λ³΄μμ. μ΄μ λΆν° μ΄λ ΅μ΅λλ€.
β
μμ΄μ§ κΈ°λ‘ μ°ΎκΈ°
μ
μμ κ° κΈ°λ‘μ μλλ°, 보νΈμμ λ€μ΄μ¨ κΈ°λ‘μ΄ μλ λλ¬Όμ IDμ μ΄λ¦μ ID μμΌλ‘ μ‘°ννλ SQLλ¬Έμ μμ±ν΄μ£ΌμΈμ.
SELECT ANIMAL_OUTS.ANIMAL_ID, ANIMAL_OUTS.NAME
FROM ANIMAL_OUTS LEFT JOIN ANIMAL_INS
ON ANIMAL_OUTS.ANIMAL_ID = ANIMAL_INS.ANIMAL_ID
WHERE ANIMAL_INS.ANIMAL_ID IS NULL;
β
μμλλ°μ μμμ΅λλ€
κ΄λ¦¬μμ μ€μλ‘ μΌλΆ λλ¬Όμ μ
μμΌμ΄ μλͺ» μ
λ ₯λμμ΅λλ€. λ³΄νΈ μμμΌλ³΄λ€ μ
μμΌμ΄ λ λΉ λ₯Έ λλ¬Όμ μμ΄λμ μ΄λ¦μ μ‘°ννλ SQLλ¬Έμ μμ±ν΄μ£ΌμΈμ. μ΄λ κ²°κ³Όλ λ³΄νΈ μμμΌμ΄ λΉ λ₯Έ μμΌλ‘ μ‘°νν΄μΌν©λλ€.
SELECT ANIMAL_INS.ANIMAL_ID, ANIMAL_INS.NAME
FROM ANIMAL_INS INNER JOIN ANIMAL_OUTS
ON ANIMAL_INS.ANIMAL_ID = ANIMAL_OUTS.ANIMAL_ID
WHERE ANIMAL_INS.DATETIME > ANIMAL_OUTS.DATETIME
ORDER BY ANIMAL_INS.DATETIME;
β
μ€λ κΈ°κ° λ³΄νΈν λλ¬Ό(1)
μμ§ μ
μμ λͺ» κ° λλ¬Ό μ€, κ°μ₯ μ€λ 보νΈμμ μμλ λλ¬Ό 3λ§λ¦¬μ μ΄λ¦κ³Ό λ³΄νΈ μμμΌμ μ‘°ννλ SQLλ¬Έμ μμ±ν΄μ£ΌμΈμ. μ΄λ κ²°κ³Όλ λ³΄νΈ μμμΌ μμΌλ‘ μ‘°νν΄μΌ ν©λλ€.
SELECT ANIMAL_INS.NAME, ANIMAL_INS.DATETIME
FROM ANIMAL_INS LEFT JOIN ANIMAL_OUTS
ON ANIMAL_INS.ANIMAL_ID = ANIMAL_OUTS.ANIMAL_ID
WHERE ANIMAL_OUTS.ANIMAL_ID IS NULL
ORDER BY ANIMAL_INS.DATETIME ASC LIMIT 3;
β
보νΈμμμ μ€μ±νν λλ¬Ό
보νΈμμμ μ€μ±ν μμ μ κ±°μΉ λλ¬Ό μ 보λ₯Ό μμλ³΄λ € ν©λλ€. 보νΈμμ λ€μ΄μ¬ λΉμμλ μ€μ±ν1λμ§ μμμ§λ§, 보νΈμλ₯Ό λκ° λΉμμλ μ€μ±νλ λλ¬Όμ μμ΄λμ μλ¬Ό μ’
, μ΄λ¦μ μ‘°ννλ μμ΄λ μμΌλ‘ μ‘°ννλ SQL λ¬Έμ μμ±ν΄μ£ΌμΈμ.
SELECT ANIMAL_OUTS.ANIMAL_ID, ANIMAL_OUTS.ANIMAL_TYPE, ANIMAL_OUTS.NAME
FROM ANIMAL_OUTS LEFT JOIN ANIMAL_INS
ON ANIMAL_OUTS.ANIMAL_ID = ANIMAL_INS.ANIMAL_ID
WHERE (ANIMAL_OUTS.SEX_UPON_OUTCOME LIKE 'Spayed%' OR ANIMAL_OUTS.SEX_UPON_OUTCOME LIKE 'Neutered%') AND ANIMAL_INS.SEX_UPON_INTAKE LIKE 'Intact%'
ORDER BY ANIMAL_OUTS.ANIMAL_ID;
π₯Summer/Winter Coding(2019)
λ°μ΄ν° λΆμ νμμλ μ°μ (Milk)μ μκ±°νΈ(Yogurt)λ₯Ό λμμ ꡬμ
ν μ₯λ°κ΅¬λκ° μλμ§ μμλ³΄λ € ν©λλ€. μ°μ μ μκ±°νΈλ₯Ό λμμ ꡬμ
ν μ₯λ°κ΅¬λμ μμ΄λλ₯Ό μ‘°ννλ SQL λ¬Έμ μμ±ν΄μ£ΌμΈμ. μ΄λ κ²°κ³Όλ μ₯λ°κ΅¬λμ μμ΄λ μμΌλ‘ λμμΌ ν©λλ€.
SELECT M.CART_ID
FROM
(SELECT CART_ID FROM CART_PRODUCTS WHERE NAME = 'Yogurt') AS M,
(SELECT CART_ID FROM CART_PRODUCTS WHERE NAME = 'Milk') AS Y
WHERE M.CART_ID = Y.CART_ID