PG SQL πŸ“Œ String,Date

imsΒ·2021λ…„ 2μ›” 26일
0

SQL

λͺ©λ‘ 보기
12/12

πŸ“Œ λ£¨μ‹œμ™€ μ—˜λΌ μ°ΎκΈ°

πŸ”₯ in

πŸ—¨ 문제

μ—¬λŸ¬ 이름듀을 μ£Όκ³ , 이름듀을 ν¬ν•¨ν•˜λŠ” 데이터 μ°ΎκΈ°

πŸ“ λ‚΄ λ‹΅

SELECT ANIMAL_ID,NAME,SEX_UPON_INTAKE FROM ANIMAL_INS
WHERE NAME = "Lucy" OR
NAME = "Ella" OR
NAME = "Pickle" OR
NAME = "Rogan" OR
NAME = "Sabrina" OR
NAME = "Mitty"
ORDER BY ANIMAL_ID

πŸ“ λ‹€λ₯Έ λ‹΅

SELECT ANIMAL_ID,NAME,SEX_UPON_INTAKE FROM ANIMAL_INS
WHERE NAME in ("Lucy","Ella","Pickle","Rogan","Sabrina","Mitty")
ORDER BY ANIMAL_ID

πŸ“Œ 이름에 EL이 λ“€μ–΄κ°€λŠ” Dog

πŸ”₯ Wildcard

https://www.w3schools.com/sql/sql_wildcards.asp

http://www.tcpschool.com/mysql/mysql_operator_patternMatching

πŸ“ λ‹΅

SELECT ANIMAL_ID,NAME FROM ANIMAL_INS
WHERE name LIKE "%EL%" AND animal_type = "Dog"
ORDER BY NAME

πŸ“Œ 쀑성화 μ—¬λΆ€ νŒŒμ•…ν•˜κΈ°

πŸ”₯ CASE - WHEN - THEN - ELSE - END

πŸ“ λ‹΅

SELECT ANIMAL_ID,NAME,
    CASE
    WHEN SEX_UPON_INTAKE LIKE "%Neutered Male%" OR SEX_UPON_INTAKE LIKE "%Spayed Female"
    THEN "O"
    ELSE "X"
    END 
    AS "쀑성화"
FROM ANIMAL_INS

πŸ“Œ 였랜 κΈ°κ°„ λ³΄ν˜Έν•œ 동물 (2)

πŸ—¨ 문제

πŸ“ 같은 Date type λΌλ¦¬λŠ” 연산이 κ°€λŠ₯ν•˜λ‹€.

SELECT INS.ANIMAL_ID,INS.NAME FROM ANIMAL_INS INS
JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
ORDER BY (OUTS.DATETIME - INS.DATETIME) DESC
LIMIT 2

πŸ“Œ DATETIMEμ—μ„œ DATE둜 ν˜•λ³€ν™˜

πŸ”₯ DATE_FORMAT(paramter,'%Y-%m-%d')

https://murra.tistory.com/157

SELECT ANIMAL_ID,NAME, DATE_FORMAT(DATETIME,'%Y-%m-%d') AS 'λ‚ μ§œ'
FROM ANIMAL_INS
ORDER BY ANIMAL_ID
profile
ν‹°μŠ€ν† λ¦¬λ‘œ μ΄μ‚¬ν–ˆμŠ΅λ‹ˆλ‹€! https://imsfromseoul.tistory.com/ + https://camel-man-ims.tistory.com/

0개의 λŒ“κΈ€