(리트코드) 585. Investments 2016

chaechae·2024년 2월 12일
0

코딩테스트(SQL) 

목록 보기
19/22
post-thumbnail

문제

2016년의 총 투자 가치 합계를 조회하는 SQL문을 작성해주세요
한 명 이상의 다른 보험 계약자와 동일한 2015년 총 투자 가치 값을 가지며, 다른 보험 계약자와 같은 도시에 있지 않는 데이터 (lat, lon 값은 중복되지 않아야 합니다).
Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all policyholders who:
have the same tiv_2015 value as one or more other policyholders, and
are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute pairs must be unique). Round tiv_2016 to two decimal places.

code


SELECT round(sum(tiv_2016),2) as tiv_2016
FROM Insurance
WHERE tiv_2015 in (SELECT tiv_2015
                    FROM Insurance
                    GROUP BY tiv_2015
                    HAVING count(tiv_2015) > 1)

AND pid in (SELECT pid
            FROM Insurance
            Group by lat, lon
            HAVING count(*) = 1)
profile
게임 혹은 다양한 컨텐츠가 있는 곳을 좋아합니다. 시리즈를 참고하시면 편하게 글을 보실 수 있습니다🫠

0개의 댓글