728x90
๋ฐ์ํ
๐ฉ์ต์๊ฐ ๊ตฌํ๊ธฐ
SELECT MIN(DATETIME)
FROM ANIMAL_INS
๐ฉ๋๋ฌผ ์ ๊ตฌํ๊ธฐ
SELECT COUNT(ANIMAL_ID)
FROM ANIMAL_INS
๐ฉ์ค๋ณต ์ ๊ฑฐํ๊ธฐ
SELECT COUNT(DISTINCT(NAME))
FROM ANIMAL_INS
WHERE NAME IS NOT NULL
๐ฉNULL ์ฒ๋ฆฌํ๊ธฐ
SELECT ANIMAL_TYPE, NVL(NAME, 'No name'), SEX_UPON_INTAKE
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
๐ฉ๊ณ ์์ด์ ๊ฐ๋ ๋ช ๋ง๋ฆฌ๊ฐ ์์๊น
SELECT ANIMAL_TYPE, COUNT(*) AS count
FROM ANIMAL_INS
GROUP BY ANIMAL_TYPE
ORDER BY ANIMAL_TYPE
๐ฉ๋๋ช ๋๋ฌผ ์ ์ฐพ๊ธฐ
SELECT NAME, COUNT(*) AS COUNT
FROM ANIMAL_INS
GROUP BY NAME
HAVING COUNT(NAME) > 1
ORDER BY NAME
๐ฉ์ ์ ์๊ฐ ๊ตฌํ๊ธฐ
SELECT HOUR, COUNT(*) COUNT
FROM (SELECT TO_CHAR(DATETIME, 'HH24') HOUR
FROM ANIMAL_OUTS)
WHERE HOUR >= 9 AND HOUR < 20
GROUP BY HOUR
ORDER BY HOUR
๐ฉ๋ฃจ์์ ์๋ผ ์ฐพ๊ธฐ
SELECT ANIMAL_ID, NAME, SEX_UPON_INTAKE
FROM ANIMAL_INS
WHERE NAME IN ( 'Lucy', 'Ella', 'Pickle', 'Rogan', 'Sabrina', 'Mitty')
ORDER BY ANIMAL_ID
๐ฉ์ด๋ฆ์ el์ด ๋ค์ด๊ฐ๋ ๋๋ฌผ ์ฐพ๊ธฐ
SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE (NAME LIKE '%El%' OR NAME LIKE '%el%') AND ANIMAL_TYPE = 'Dog'
ORDER BY NAME
๐ฉ์ค์ฑํ ์ฌ๋ถ ํ์ ํ๊ธฐ
SELECT ANIMAL_ID, NAME,
CASE WHEN SEX_UPON_INTAKE LIKE 'Spayed%' THEN 'O'
WHEN SEX_UPON_INTAKE LIKE 'Neutered%' THEN 'O'
ELSE 'X'
END
AS ์ค์ฑํ
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
๐ฉDATETIME์์ DATE๋ก ํ ๋ณํ
SELECT ANIMAL_ID, NAME, TO_CHAR(DATETIME, 'YYYY-MM-DD') ๋ ์ง
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
๋ฐ์ํ
'Engineering > SQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] SQL LEVEL 1 ์ ์ฒด /Oracle /์ค๋ผํด /SELECT (0) | 2020.09.26 |
---|