๐Ÿ’ SQL/Is Null

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ์žก์€ ๋ฌผ๊ณ ๊ธฐ์˜ ํ‰๊ท  ๊ธธ์ด ๊ตฌํ•˜๊ธฐ (293259)

์„ ๋‹ฌ 2024. 10. 19. 03:30
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

์žก์€ ๋ฌผ๊ณ ๊ธฐ์˜ ํ‰๊ท  ๊ธธ์ด๋ฅผ ์ถœ๋ ฅํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

ํ‰๊ท  ๊ธธ์ด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ปฌ๋Ÿผ ๋ช…์€ AVERAGE_LENGTH๋กœ ํ•ด์ฃผ์„ธ์š”.

ํ‰๊ท  ๊ธธ์ด๋Š” ์†Œ์ˆ˜์  3์งธ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•˜๋ฉฐ, 10cm ์ดํ•˜์˜ ๋ฌผ๊ณ ๊ธฐ๋“ค์€ 10cm ๋กœ ์ทจ๊ธ‰ํ•˜์—ฌ ํ‰๊ท  ๊ธธ์ด๋ฅผ ๊ตฌํ•ด์ฃผ์„ธ์š”.

 

ํ’€์ด

select round(avg(len), 2) as AVERAGE_LENGTH
from ( 
    select 
        case when LENGTH is null then 10
        else LENGTH
        end as len
    from FISH_INFO
    ) as min_length_10
๋ฐ˜์‘ํ˜•