์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์žˆ์—ˆ๋Š”๋ฐ์š” ์—†์—ˆ์Šต๋‹ˆ๋‹ค (SQL/JOIN)

PROGRAMMING/Database

by koharin 2021. 1. 23. 02:20

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ป MYSQL ์ œ์ถœ์ฝ”๋“œ


SELECT A.ANIMAL_ID, A.NAME
FROM ANIMAL_INS A
INNER JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE A.DATETIME > B.DATETIME
ORDER BY A.DATETIME ASC;

 

๐Ÿ“ ๋ฌธ์ œํ’€์ด ๊ณผ์ •


  • ANIMAL_ID๋ฅผ ๊ธฐ์ค€์œผ๋กœ INNER JOIN์„ ํ•œ๋‹ค.

  • WHERE: ๊ฑฐ๊ธฐ์—์„œ ANIMAL_INS.DATETIME > ANIMAL_OUTS.DATETIME์ธ ์กฐ๊ฑด์„ ์กฐํšŒํ•œ๋‹ค.

  • ORDER BY: ANIMAL_INS ๊ธฐ์ค€ DATETIME์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

SELECT A.ANIMAL_ID, A.NAME, A.DATETIME AS in_time, B.DATETIME AS out_time
FROM ANIMAL_INS A
INNER JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE A.DATETIME > B.DATETIME
ORDER BY A.DATETIME ASC;

  • ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋Š” ์œ„์™€ ๊ฐ™์ด ๋‚˜์˜จ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ