inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Biggest Single Number (가장 큰 단일 숫자)

    Stupefyee's avatar
    Stupefyee
    May 27, 2025
    [SQL 문제 풀이] Biggest Single Number (가장 큰 단일 숫자)
    Contents
    내가 작성한 쿼리
    Biggest Single Number - LeetCode
    Can you solve this real interview question? Biggest Single Number - Table: MyNumbers +-------------+------+ | Column Name | Type | +-------------+------+ | num | int | +-------------+------+ This table may contain duplicates (In other words, there is no primary key for this table in SQL). Each row of this table contains an integer.   A single number is a number that appeared only once in the MyNumbers table. Find the largest single number. If there is no single number, report null. The result format is in the following example.   Example 1: Input: MyNumbers table: +-----+ | num | +-----+ | 8 | | 8 | | 3 | | 3 | | 1 | | 4 | | 5 | | 6 | +-----+ Output: +-----+ | num | +-----+ | 6 | +-----+ Explanation: The single numbers are 1, 4, 5, and 6. Since 6 is the largest single number, we return it. Example 2: Input: MyNumbers table: +-----+ | num | +-----+ | 8 | | 8 | | 7 | | 7 | | 3 | | 3 | | 3 | +-----+ Output: +------+ | num | +------+ | null | +------+ Explanation: There are no single numbers in the input table so we return null.
    Biggest Single Number - LeetCode
    https://leetcode.com/problems/biggest-single-number/description/
    Biggest Single Number - LeetCode
    notion image
    단일 숫자는 MyNumbers 표에 단 한 번만 표시된 숫자입니다. 가장 큰 단일 숫자를 찾습니다. 단일 숫자가 없는 경우 null을 보고합니다.
     

    내가 작성한 쿼리

    MySQL, Oracle

    SELECT MAX(num) AS num -- 중복이 없는 것들만 조회하는 서브쿼리 FROM ( SELECT num FROM MyNumbers GROUP BY num HAVING COUNT(*) = 1 ) unique_nums;
     
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog