0% found this document useful (0 votes)
14 views2 pages

Nhap 2

The document contains a series of SQL queries related to various database operations, including selecting, deleting, and aggregating data. It covers topics such as identifying consecutive numbers, filtering big countries, calculating average processing times, and managing duplicate emails. Additionally, it includes queries for finding specific records based on conditions related to instructors, courses, and weather data.

Uploaded by

huytam514z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Nhap 2

The document contains a series of SQL queries related to various database operations, including selecting, deleting, and aggregating data. It covers topics such as identifying consecutive numbers, filtering big countries, calculating average processing times, and managing duplicate emails. Additionally, it includes queries for finding specific records based on conditions related to instructors, courses, and weather data.

Uploaded by

huytam514z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL132 - Làm quen với LearnSQL

=>
select * from learnsql
SQL94 - Consecutive number
SELECT DISTINCT l1.num AS ConsecutiveNums
FROM Logs l1
JOIN Logs l2 ON l1.id = l2.id - 1
JOIN Logs l3 ON l1.id = l3.id - 2
WHERE l1.num = l2.num AND l2.num = l3.num;
SQL95 - Big Countries
SELECT name, population, area
FROM World
WHERE area >= 3000000 OR population >= 25000000;

SQL97 - Average time of process per machine


SELECT
machine_id,
ROUND(AVG(end_time - start_time), 3) AS processing_time
FROM (
SELECT
machine_id,
process_id,
MAX(CASE WHEN activity_type = 'end' THEN timestamp END) AS end_time,
MAX(CASE WHEN activity_type = 'start' THEN timestamp END) AS start_time
FROM Activity
GROUP BY machine_id, process_id
) process_times
GROUP BY machine_id;

SQL98 - Delete duplicate emails


DELETE FROM Person
WHERE id NOT IN (
SELECT MIN(id)
FROM Person
GROUP BY email
);

SQL99 - Find custom referee


SELECT name
FROM Customer
WHERE referee_id IS NULL OR referee_id != 2;
SQL100 - Recycle and low fat product
SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y';
SQL101 - Not boring movie
SELECT id, movie, description, rating
FROM Cinema
WHERE id % 2 != 0
AND description != 'boring'
ORDER BY rating DESC;

SQL102 - Rising temperature


SELECT w1.id
FROM Weather w1
JOIN Weather w2 ON DATE_ADD(w2.recordDate, INTERVAL 1 DAY) = w1.recordDate
WHERE w1.temperature > w2.temperature;

SQL103 - Liệt kê 2 khóa học theo tên giảng viên (sắp xếp theo tên giảm dần)
SELECT i.username, t.dept, t.number
FROM Teaches t
JOIN Instructor i ON t.username = i.username
JOIN Class c ON t.dept = c.dept AND t.number = c.number
ORDER BY i.lname DESC,i.fname DESC
limit 2
SQL106 - Tìm firstname của Instructor
SELECT fname
FROM Instructor
WHERE username = 'zahorjan';

SQL107 - Các khóa học cấp độ 400 (4xx) của CSE đang mở là gì
SELECT c.dept, c.number, c.title
FROM Class c
JOIN Teaches t ON c.dept = t.dept AND c.number = t.number
JOIN Instructor i ON t.username = i.username
WHERE c.dept = 'CSE' AND c.number BETWEEN 400 AND 499
GROUP BY c.dept, c.number, c.title;

You might also like