LeetCode SQL Questions

511. Game Play Analysis I

511. Game Play Analysis I

Transact-SQL

1
2
3
SELECT player_id AS 'player_id', MIN(event_date) AS 'first_login' 
FROM Activity
GROUP BY player_id

Submission Detail

  • 12 / 12 test cases passed.
  • Runtime: 2929 ms, faster than 51.13% of MS SQL Server online submissions for Game Play Analysis I.
  • Memory Usage: 0B, less than 100.00% of MS SQL Server online submissions for Game Play Analysis I.

584. Find Customer Referee

584. Find Customer Referee

Transact-SQL

1
2
SELECT CU.name FROM Customer AS CU 
WHERE CU.referee_id is null OR CU.referee_id <> 2

Submission Detail

  • 19 / 19 test cases passed.
  • Runtime: 972 ms, faster than 63.09% of MS SQL Server online submissions for Find Customer Referee.
  • Memory Usage: 0B, less than 100.00% of MS SQL Server online submissions for Find Customer Referee.

586. Customer Placing the Largest Number of Orders

586. Customer Placing the Largest Number of Orders

Transact-SQL

1
2
3
4
5
6
7
SELECT TOP 1 V.customer_number AS 'customer_number' FROM 
(
SELECT O.customer_number AS 'customer_number', COUNT(O.order_number) AS 'num'
FROM Orders AS O
GROUP BY O.customer_number
) AS V
ORDER BY V.num DESC

Submission Detail

  • 20 / 20 test cases passed.
  • Runtime: 779 ms, faster than 90.16% of MS SQL Server online submissions for Customer Placing the Largest Number of Orders.
  • Memory Usage: 0B, less than 100.00% of MS SQL Server online submissions for Customer Placing the Largest Number of Orders.

607. Sales Person

607. Sales Person

Transact-SQL

1

1
2
3
4
5
6
7
SELECT SP.name AS 'name' FROM SalesPerson AS SP 
WHERE SP.sales_id NOT IN
(
SELECT O.sales_id FROM Company AS C
JOIN Orders AS O ON O.com_id = C.com_id
WHERE C.name = 'RED'
)

Submission Detail

  • 20 / 20 test cases passed.
  • Runtime: 2418 ms, faster than 5.03% of MS SQL Server online submissions for Sales Person.
  • Memory Usage: 0B, less than 100.00% of MS SQL Server online submissions for Sales Person.

2

1
2
3
4
5
6
7
8
9
SELECT SP.name AS 'name' FROM SalesPerson AS SP 
LEFT OUTER JOIN
(
SELECT O.sales_id, O.order_id FROM Company AS C
JOIN Orders AS O ON O.com_id = C.com_id
WHERE C.name = 'RED'
) AS V
ON SP.sales_id = V.sales_id
WHERE V.order_id IS NULL

Submission Detail

  • 20 / 20 test cases passed.
  • Runtime: 859 ms, faster than 96.62% of MS SQL Server online submissions for Sales Person.
  • Memory Usage: 0B, less than 100.00% of MS SQL Server online submissions for Sales Person.