15 Days of Learning SQL

  • + 0 comments

    What is wrong with the following?

    WITH tot_subm AS (``
        SELECT 
            s.submission_date,
            COUNT(s.submission_id) AS total_submissions,
            h.hacker_id,
            h.name,
            ROW_NUMBER() OVER (
                PARTITION BY s.submission_date 
                ORDER BY COUNT(s.submission_id) DESC, h.hacker_id ASC
            ) AS r_numb
        FROM Hackers h
        INNER JOIN Submissions s ON s.hacker_id = h.hacker_id
        WHERE s.submission_date BETWEEN '2016-03-01' AND '2016-03-15'
        GROUP BY s.submission_date, h.hacker_id, h.name
    )
    SELECT 
        submission_date, 
        total_submissions, 
        hacker_id, 
        name        
    FROM tot_subm    
    WHERE r_numb = 1
    ORDER BY submission_date;