[SQL๋ฌธ์ ํ๊ธฐ - Advent of SQL 2025 ๐ ] DVD ๋์ฌ์ ์ฐ์ ๊ณ ๊ฐ ์ฐพ๊ธฐ
Dec 06, 2025
๋ฌธ์
๋ด๊ฐ ์์ฑํ ์ค๋ต
select distinct active from customer; active๊ฐ 1์ด๋ฉด ์ ํจ๊ณ ๊ฐ 0์ด๋ฉด ๋ฌดํจ๊ณ ๊ฐ?์ด์๋ค.


๋ด๊ฐ ์์ฑํ ์ ๋ต
MySQL, SQLlite
select r.customer_id
from rental r
join customer c on r.customer_id = c.customer_id and c.active = 1
group by r.customer_id
having count(distinct r.rental_id) >= 35;PostgreSQL
: PostgreSQL์์๋ active์ ํ์
์ด boolean์ผ๋ก ์ ์ฅ๋ผ์์๋ค.
select r.customer_id
from rental r
join customer c on r.customer_id = c.customer_id and c.active
group by r.customer_id
having count(distinct r.rental_id) >= 35;Share article