강의

멘토링

커뮤니티

Inflearn Community Q&A

escho04's profile image
escho04

asked

Kim Young-han's Practical Database - Fundamentals

Correlated Subquery1

where 대신 having을 써도 되나요?

Written on

·

51

0


[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)

[질문 내용]
select * from products p1

where price >= (

select avg(p2.price) from products p2 where p2.category = p1.category);

대신에

select name,price from products p1

where price >= (select avg(p2.price) from products p2

group by category

having p1.category=p2.category);

으로 써도 문제 없나요?

sqlmysqldbms/rdbmsSQLD

Answer 1

0

안녕하세요. escho94님, 공식 서포터즈 David입니다.

네, 후자로 작성하셔도 됩니다.

다만, 전자 대비 불필요한 연산이 추가되는 단점이 있습니다.

감사합니다.

escho04's profile image
escho04

asked

Ask a question