This is the multi-page printable view of this section. Click here to print.
Sql
Sql projects
- 1: Leetcode submissions
- 1.1: 2025-08-10 10:14:07 +0000 UTC
- 1.2: 2025-08-10 10:10:37 +0000 UTC
- 1.3: 2025-08-10 09:56:18 +0000 UTC
- 1.4: 2025-08-10 09:52:07 +0000 UTC
- 1.5: 2025-08-10 08:14:30 +0000 UTC
- 1.6: 2025-08-07 14:57:34 +0000 UTC
- 1.7: 2025-08-06 16:26:47 +0000 UTC
- 1.8: 2025-08-03 11:36:46 +0000 UTC
- 1.9: 2025-08-03 11:29:35 +0000 UTC
- 1.10: 2025-08-03 11:14:27 +0000 UTC
- 1.11: 2025-08-02 17:09:46 +0000 UTC
- 1.12: 2025-08-02 16:28:39 +0000 UTC
- 1.13: 2025-08-02 15:33:48 +0000 UTC
- 1.14: 2025-08-02 14:24:46 +0000 UTC
- 1.15: 2025-08-02 13:25:49 +0000 UTC
- 1.16: 2025-08-02 12:46:47 +0000 UTC
- 1.17: 2025-08-02 12:01:25 +0000 UTC
- 1.18: 2025-08-02 11:21:50 +0000 UTC
- 1.19: 2025-08-02 11:15:20 +0000 UTC
- 1.20: 2025-08-02 09:22:49 +0000 UTC
- 1.21: 2025-08-02 07:56:41 +0000 UTC
- 1.22: 2025-08-02 07:53:44 +0000 UTC
- 1.23: 2025-08-02 07:46:44 +0000 UTC
- 1.24: 2025-08-02 07:41:17 +0000 UTC
- 1.25: 2025-07-30 17:52:44 +0000 UTC
- 1.26: 2025-07-30 17:47:51 +0000 UTC
- 1.27: 2025-07-30 17:42:31 +0000 UTC
- 1.28: 2025-07-30 17:12:39 +0000 UTC
- 1.29: 2025-07-30 17:09:55 +0000 UTC
- 1.30: 2025-07-30 17:05:18 +0000 UTC
- 1.31: 2025-07-30 16:18:29 +0000 UTC
- 1.32: 2025-07-30 16:14:46 +0000 UTC
- 1.33: 2025-07-30 15:32:15 +0000 UTC
- 1.34: 2025-07-30 15:31:28 +0000 UTC
- 1.35: 2025-07-30 15:25:43 +0000 UTC
- 1.36: 2025-07-30 15:19:10 +0000 UTC
- 1.37: 2025-07-29 18:27:41 +0000 UTC
- 1.38: 2025-07-29 13:37:09 +0000 UTC
- 1.39: 2025-07-29 13:11:49 +0000 UTC
- 1.40: 2025-07-28 17:06:14 +0000 UTC
- 1.41: 2025-07-28 13:45:20 +0000 UTC
- 1.42: 2025-07-28 13:35:55 +0000 UTC
- 1.43: 2025-07-25 09:18:12 +0000 UTC
- 2: Bazel targets
- 3: Changelog
1 - Leetcode submissions
1.1 - 2025-08-10 10:14:07 +0000 UTC
Daily Leads and Partners
Links
Code
SELECT
DailySales.date_id,
DailySales.make_name,
COUNT(DISTINCT DailySales.lead_id) AS unique_leads,
COUNT(DISTINCT DailySales.partner_id) AS unique_partners
FROM
DailySales
GROUP BY
DailySales.date_id,
DailySales.make_name;
1.2 - 2025-08-10 10:10:37 +0000 UTC
Invalid Tweets
Links
Code
SELECT
Tweets.tweet_id
FROM
Tweets
WHERE
LENGTH(Tweets.content) > 15
1.3 - 2025-08-10 09:56:18 +0000 UTC
Fix Names in a Table
Links
Code
SELECT
Users.user_id,
UPPER(LEFT(Users.name, 1))
|| LOWER(SUBSTRING(Users.name FROM 2)) AS name
FROM
Users
ORDER BY
Users.user_id;
1.4 - 2025-08-10 09:52:07 +0000 UTC
Average Time of Process per Machine
Links
Code
SELECT
act1.machine_id,
ROUND(AVG(act2.timestamp - act1.timestamp)::decimal, 3) AS processing_time
FROM
Activity act1,
Activity act2
WHERE
act1.machine_id = act2.machine_id
AND act1.process_id = act2.process_id
AND act1.activity_type = 'start'
AND act2.activity_type = 'end'
GROUP BY
act1.machine_id;
1.5 - 2025-08-10 08:14:30 +0000 UTC
Percentage of Users Attended a Contest
Links
Code
WITH total_users AS (
SELECT
COUNT(DISTINCT user_id) AS total_count
FROM
Users
)
SELECT
Register.contest_id,
ROUND(
COUNT(DISTINCT Register.user_id) * 100.0 / total_users.total_count,
2
) AS percentage
FROM
Register
CROSS JOIN
total_users
GROUP BY
Register.contest_id,
total_users.total_count
ORDER BY
percentage DESC,
Register.contest_id;
1.6 - 2025-08-07 14:57:34 +0000 UTC
Bank Account Summary II
Links
Code
SELECT
Users.name AS "NAME",
SUM(Transactions.amount) AS "BALANCE"
FROM
Users
LEFT JOIN
Transactions
ON
Users.account = Transactions.account
GROUP BY
Users.account, Users.name
HAVING
SUM(Transactions.amount) > 10000
1.7 - 2025-08-06 16:26:47 +0000 UTC
Customer Who Visited but Did Not Make Any Transactions
Links
Code
SELECT
Visits.customer_id,
COUNT(Visits.visit_id) AS "count_no_trans"
FROM
Visits
LEFT JOIN
Transactions
ON
Visits.visit_id = Transactions.visit_id
WHERE
Transactions.visit_id IS NULL
GROUP BY
Visits.customer_id
1.8 - 2025-08-03 11:36:46 +0000 UTC
Patients With a Condition
Links
Code
SELECT
Patients.patient_id,
Patients.patient_name,
Patients.conditions
FROM
Patients
WHERE
Patients.conditions ~ '(^|\s)DIAB1'
1.9 - 2025-08-03 11:29:35 +0000 UTC
Find Users With Valid E-Mails
Links
Code
SELECT
*
FROM
Users
WHERE
Users.mail ~ '^[a-zA-Z][a-zA-Z0-9\.\-_]*@leetcode\.com$';
1.10 - 2025-08-03 11:14:27 +0000 UTC
Group Sold Products By The Date
Links
Code
SELECT
Activities.sell_date,
COUNT(
DISTINCT (Activities.product, Activities.sell_date)
) AS num_sold,
STRING_AGG(
DISTINCT Activities.product, ',' ORDER BY product
) AS products
FROM
Activities
GROUP BY
Activities.sell_date
ORDER BY
Activities.sell_date;
1.11 - 2025-08-02 17:09:46 +0000 UTC
Top Travellers
Links
Code
SELECT
Users.name,
COALESCE(SUM(Rides.distance), 0) AS "travelled_distance"
FROM
Users
LEFT JOIN
Rides
ON
Users.id = Rides.user_id
GROUP BY
Users.id, Users.name
ORDER BY
travelled_distance DESC,
Users.name ASC
1.12 - 2025-08-02 16:28:39 +0000 UTC
Replace Employee ID With The Unique Identifier
Links
Code
SELECT
EmployeeUNI.unique_id, Employees.name
FROM
Employees
LEFT JOIN
EmployeeUNI
ON
Employees.id = EmployeeUNI.id
1.13 - 2025-08-02 15:33:48 +0000 UTC
List the Products Ordered in a Period
Links
Code
SELECT
Products.product_name, SUM(Orders.unit) as "unit"
FROM
Products
JOIN
Orders
ON
Orders.product_id = Products.product_id
WHERE
Orders.order_date BETWEEN '2020-02-01' AND '2020-02-29'
GROUP BY
Products.product_name
HAVING
SUM(Orders.unit) >= 100;
1.14 - 2025-08-02 14:24:46 +0000 UTC
Students and Examinations
Links
Code
SELECT
Students.student_id,
Students.student_name,
Subjects.subject_name,
COUNT(Examinations.subject_name) as "attended_exams"
FROM
Students
CROSS JOIN
Subjects
LEFT JOIN
Examinations
ON
Students.student_id = Examinations.student_id
AND Subjects.subject_name = Examinations.subject_name
GROUP BY
Students.student_id,
Students.student_name,
Subjects.subject_name
ORDER BY
Students.student_id,
Subjects.subject_name
1.15 - 2025-08-02 13:25:49 +0000 UTC
Average Selling Price
Links
Code
SELECT
Prices.product_id,
CASE
WHEN
SUM(UnitsSold.units) is null
THEN
0
ELSE
ROUND(SUM(UnitsSold.units * Prices.price) / SUM(UnitsSold.units)::numeric, 2)
END AS average_price
FROM
Prices
LEFT JOIN
UnitsSold
ON
UnitsSold.product_id = Prices.product_id
AND UnitsSold.purchase_date
BETWEEN Prices.start_date AND Prices.end_date
GROUP BY
Prices.product_id;
1.16 - 2025-08-02 12:46:47 +0000 UTC
Queries Quality and Percentage
Links
Code
SELECT
query_name,
ROUND(SUM(rating * 1.0 / position) / COUNT(*), 2) AS quality,
ROUND(
COUNT(CASE WHEN rating < 3 THEN 1 END) * 1.0 / COUNT(*),
4
) * 100 AS poor_query_percentage
FROM
Queries
GROUP BY
query_name;
1.17 - 2025-08-02 12:01:25 +0000 UTC
Reformat Department Table
Links
Code
SELECT id,
SUM(
CASE
WHEN
month = 'Jan'
THEN
revenue
ELSE
NULL
END
) AS Jan_Revenue,
SUM(
CASE
WHEN
month = 'Feb'
THEN
revenue
ELSE
NULL
END
) AS Feb_Revenue,
SUM(
CASE
WHEN
month = 'Mar'
THEN
revenue
ELSE
NULL
END
) AS Mar_Revenue,
SUM(
CASE
WHEN
month = 'Apr'
THEN
revenue
ELSE
NULL
END
) AS Apr_Revenue,
SUM(
CASE
WHEN
month = 'May'
THEN
revenue
ELSE
NULL
END
) AS May_Revenue,
SUM(
CASE
WHEN
month = 'Jun'
THEN
revenue
ELSE
NULL
END
) AS Jun_Revenue,
SUM(
CASE
WHEN
month = 'Jul'
THEN
revenue
ELSE
NULL
END
) AS Jul_Revenue,
SUM(
CASE
WHEN
month = 'Aug'
THEN
revenue
ELSE
NULL
END
) AS Aug_Revenue,
SUM(
CASE
WHEN
month = 'Sep'
THEN
revenue
ELSE
NULL
END
) AS Sep_Revenue,
SUM(
CASE
WHEN
month = 'Oct'
THEN
revenue
ELSE
NULL
END
) AS Oct_Revenue,
SUM(
CASE
WHEN
month = 'Nov'
THEN
revenue
ELSE
NULL
END
) AS Nov_Revenue,
SUM(
CASE
WHEN
month = 'Dec'
THEN
revenue
ELSE
NULL
END
) AS Dec_Revenue
FROM
Department
GROUP BY
id;
1.18 - 2025-08-02 11:21:50 +0000 UTC
Article Views I
Links
Code
SELECT DISTINCT
views1.author_id as "id"
FROM
Views views1
CROSS JOIN
Views views2
WHERE
views1.author_id = views2.viewer_id
AND views1.author_id = views2.author_id
ORDER BY
views1.author_id ASC
1.19 - 2025-08-02 11:15:20 +0000 UTC
User Activity for the Past 30 Days I
Links
Code
SELECT
activity_date AS day,
COUNT(DISTINCT(user_id)) AS active_users
FROM
Activity
WHERE
activity_date
BETWEEN '2019-07-27'::DATE - INTERVAL '29 DAYS'
AND '2019-07-27'::DATE
GROUP BY
activity_date
1.20 - 2025-08-02 09:22:49 +0000 UTC
Sales Analysis III
Links
Code
SELECT
Product.product_id, Product.product_name
FROM
Sales
JOIN
Product
ON
Product.product_id = Sales.product_id
GROUP BY
Product.product_id, Product.product_name
HAVING
MIN(Sales.sale_date) >= '2019-01-01'
AND MAX(Sales.sale_date) <= '2019-03-31'
1.21 - 2025-08-02 07:56:41 +0000 UTC
Project Employees I
Links
Code
SELECT
project_id,
ROUND(AVG(experience_years), 2) AS average_years
FROM
Project
JOIN
Employee
ON
Project.employee_id = Employee.employee_id
GROUP BY
project_id
1.22 - 2025-08-02 07:53:44 +0000 UTC
Project Employees I
Links
Code
SELECT
project_id,
ROUND(AVG(experience_years), 2) AS average_years
FROM
Project
JOIN
Employee
ON
Project.employee_id = Employee.employee_id
GROUP BY
project_id
1.23 - 2025-08-02 07:46:44 +0000 UTC
Product Sales Analysis I
Links
Code
SELECT
product_name, year, price
FROM
Sales
LEFT JOIN
Product
ON
Sales.product_id = Product.product_id
1.24 - 2025-08-02 07:41:17 +0000 UTC
Actors and Directors Who Cooperated At Least Three Times
Links
Code
SELECT
actor_id, director_id
FROM
ActorDirector
GROUP BY
actor_id, director_id
HAVING
COUNT(actor_id) >= 3;
1.25 - 2025-07-30 17:52:44 +0000 UTC
Swap Salary
Links
Code
UPDATE
Salary
SET
sex = (
CASE
WHEN
sex = 'f'
THEN
'm'
ELSE
'f'
END
);
1.26 - 2025-07-30 17:47:51 +0000 UTC
Not Boring Movies
Links
Code
SELECT
id, movie, description, rating
FROM
Cinema
WHERE
description != 'boring'
AND id % 2 != 0
ORDER BY
rating DESC;
1.27 - 2025-07-30 17:42:31 +0000 UTC
Biggest Single Number
Links
Code
WITH nums AS (
SELECT
num
FROM
MyNumbers
GROUP BY
num
HAVING
COUNT(num) = 1
)
SELECT
MAX(num) AS num
FROM
nums;
1.28 - 2025-07-30 17:12:39 +0000 UTC
Triangle Judgement
Links
Code
SELECT
x, y, z, (
CASE
WHEN
((x+y+z) - GREATEST(x,y,z)) > GREATEST(x,y,z)
THEN
'Yes'
ELSE
'No'
END
) AS triangle
FROM
Triangle;
1.29 - 2025-07-30 17:09:55 +0000 UTC
Triangle Judgement
Links
Code
(
SELECT
x, y, z, 'Yes' AS triangle
FROM
Triangle
WHERE
(x + y > z) AND (y + z > x) AND (z + x > y)
) UNION (
SELECT
x, y, z, 'No' AS triangle
FROM
Triangle
WHERE (x + y <= z) OR (y + z <= x) OR (z + x <= y)
);
1.30 - 2025-07-30 17:05:18 +0000 UTC
Sales Person
Links
Code
SELECT
sales_person.name
FROM (
Orders orders
JOIN
Company company
ON
orders.com_id = company.com_id
AND company.name = 'RED'
RIGHT JOIN
SalesPerson sales_person
ON
sales_person.sales_id = orders.sales_id
)
WHERE
orders.sales_id IS NULL;
1.31 - 2025-07-30 16:18:29 +0000 UTC
Classes With at Least 5 Students
Links
Code
SELECT
class
FROM
Courses
GROUP BY
class
HAVING
COUNT(class) >= 5;
1.32 - 2025-07-30 16:14:46 +0000 UTC
Big Countries
Links
Code
SELECT
World.name, World.population, World.area
FROM
World
WHERE
World.area >= 3000000
OR World.population >= 25000000;
1.33 - 2025-07-30 15:32:15 +0000 UTC
Customer Placing the Largest Number of Orders
Links
Code
SELECT
Orders.customer_number
FROM
Orders
GROUP BY
Orders.customer_number
ORDER BY
COUNT(Orders.customer_number) DESC
LIMIT
1;
1.34 - 2025-07-30 15:31:28 +0000 UTC
Customer Placing the Largest Number of Orders
Links
Code
SELECT
Orders.customer_number
FROM
Orders
GROUP BY
Orders.customer_number
ORDER BY
COUNT(*) DESC
LIMIT
1;
1.35 - 2025-07-30 15:25:43 +0000 UTC
Find Customer Referee
Links
Code
SELECT
Customer.name
FROM
Customer
WHERE
Customer.referee_id != 2
OR Customer.referee_id IS NULL
1.36 - 2025-07-30 15:19:10 +0000 UTC
Employee Bonus
Links
Code
SELECT
Employee.name, Bonus.bonus
FROM
Employee
LEFT JOIN
Bonus
ON
Employee.empId = Bonus.empId
WHERE
Bonus.bonus IS NULL
OR Bonus.bonus < 1000
1.37 - 2025-07-29 18:27:41 +0000 UTC
Game Play Analysis I
Links
Code
SELECT
player_id, MIN(event_date) as "first_login"
FROM
Activity
GROUP BY
player_id
1.38 - 2025-07-29 13:37:09 +0000 UTC
Delete Duplicate Emails
Links
Code
DELETE FROM
Person
WHERE
id NOT IN (
SELECT MIN(id) FROM Person
GROUP BY email
)
;
1.39 - 2025-07-29 13:11:49 +0000 UTC
Rising Temperature
Links
Code
SELECT
today.id
FROM
Weather today
CROSS JOIN
Weather yesterday
WHERE
(today.recordDate - yesterday.recordDate = 1)
AND today.temperature > yesterday.temperature
1.40 - 2025-07-28 17:06:14 +0000 UTC
Employees Earning More Than Their Managers
Links
Code
SELECT employee.name AS Employee
FROM Employee employee
JOIN Employee manager
ON employee.managerId = manager.id
WHERE employee.salary > manager.salary;
1.41 - 2025-07-28 13:45:20 +0000 UTC
Customers Who Never Order
Links
Code
SELECT name as "Customers"
FROM Customers
WHERE id NOT IN (
SELECT customerId
FROM Orders
);
1.42 - 2025-07-28 13:35:55 +0000 UTC
Duplicate Emails
Links
Code
SELECT email FROM Person
GROUP BY email
HAVING COUNT(email) > 1;
1.43 - 2025-07-25 09:18:12 +0000 UTC
Combine Two Tables
Links
Code
SELECT firstName, lastName, city, state
FROM Person LEFT JOIN Address
ON Person.personId = Address.personId
2 - Bazel targets
Name | Info | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
changelog |
|
||||||||||
changelog-changelog |
|
||||||||||
changelog-changelog-data |
|
||||||||||
changelog-children |
|
||||||||||
changelog-template |
|
||||||||||
readme |
|
||||||||||
readme-children |
|
3 - Changelog
- Update leetcode (e43773)