본문 바로가기

분류 전체보기86

[LeetCode/MSSQL] 262. Trips and Users 문제링크 262. Trips and Users https://leetcode.com/problems/trips-and-users/description/ 기억하면 좋을 것 select request_at day ,round(sum(case when status = 'cancelled_by_driver' or status = 'cancelled_by_client' then 1 else 0 end) / (count(id) * 1.00),2) 'Cancellation Rate' from Trips t where request_at between '2013-10-01' and '2013-10-03' and client_id in (select users_id from Users where banned = 'No'.. 2024. 4. 6.
[MSSQL] JOIN시 ON 절에 조건을 붙여줄 때 주의할 점 INNER JOIN 은 두 테이블에서 조인할 때 , 두 테이블에 모두 지정한 열의 데이터가 있어야한다. OUTER JOIN 은 두 테이블에서 조인할 때, 1개의 테이블에만 데이터가 있어도 결과가 나온다. ON 절은 join 조건을 정의할때 사용하고 Where 은 데이터 필터링을 할 때 사용해야한다. "사용해야한다" 라고 말하는 이유는 이렇게 해야 쿼리를 더 읽기 쉽게 짤 수 있고 잘못된 데이터를 가져오는 것을 막을 수 있기 때문이다. 예시 Inner join 절에 P.ProductID = '2' 같은 필터링 조건을 붙여줬을때는 상관이 없지만 필터링한 결과가 나오지만 같은 조건에 Left outer join 을 한 경우 Left outer join 이 모든 row 를 가져와버린다. 이 경우 P.Produc.. 2024. 3. 31.
[LeetCode/MSSQL] 1327. List the Products Ordered in a Period 문제링크 1327. List the Products Ordered in a Period https://leetcode.com/problems/list-the-products-ordered-in-a-period/description/?envType=study-plan-v2&envId=top-sql-50 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이과정 생.. 2024. 1. 28.
[LeetCode/MSSQL] 196. Delete Duplicate Emails 문제링크 196. Delete Duplicate Emails https://leetcode.com/problems/delete-duplicate-emails/description/?envType=study-plan-v2&envId=top-sql-50 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이과정 시도 1. 테이블 GROUP BY email 로 묶어서.. 2024. 1. 28.