SQL 教程链接:https://www.lintcode.com/learn
LEVEL1:
2045 · Output Hello LintCode
1
SELECT "Hello LintCode!";
2013 · Check the name of the teacher
1
SELECT `name` FROM `teachers`
2007 · Check course name and class size
1
SELECT `name`,`student_count` FROM courses
2009 · Query all teachers
1
SELECT * FROM `teachers`
1981 · Check the nationality of all teachers
1
SELECT DISTINCT country FROM teachers
2011.Search for information on courses with more than 1000 participants
1
SELECT * FROM `courses` WHERE `student_count`>1000
2012 · Find course information for the course named Artificial Intelligence
1
SELECT * FROM courses WHERE `name`= 'Artificial Intelligence';
2017 · Inserting SQL course information into the course table
1
INSERT INTO courses VALUES (14,"SQL",200,"2021-02-25",1)
2021 · Insert teacher information into the specified column of the teachers table
1
2INSERT INTO `teachers` (`name`,`email`,`age`,`country`) VALUES
('XiaoFu','XiaoFu@lintcode.com',20,'CN');2020 · Update on the number of students choosing artificial intelligence
1
UPDATE `courses` SET `student_count`=500 WHERE `name`='Artificial Intelligence'
2004 · Delete all courses until 2020
1
DELETE FROM `courses` WHERE `created_at`<'2020-1-1'
2019 · Delete all rows in the table
1
DELETE FROM `courses`
LEVEL2:
1952 · Query teachers over 20 years old
1
SELECT * FROM `teachers` WHERE `age`>20
1953 · Query the name of the Chinese teacher
1
SELECT `name` FROM `teachers` WHERE `country`='CN'
1957 · Inquire about courses starting before May 2020
1
SELECT `name`,`created_at` FROM `courses` WHERE `created_at`>='2020-1-1' AND `created_at`<'2020-5-1'
1958 · Query the courses that meet the conditions taught by the specified teacher
1
SELECT * FROM `courses` WHERE `teacher_id`=4 AND `student_count`>500
2001 · Query the course information of ‘Web’ or ‘Big Data’
1
SELECT * FROM `courses`WHERE `name`='Web' OR `name`='Big Data';
2040 · Search for courses with an instructor id of less than 3 and more than 800 students
1
SELECT * FROM `courses` WHERE (NOT `teacher_id`=3) AND (`student_count`>800);
1960 · Query course information for a specific time
1
SELECT * FROM `courses` WHERE created_at IN ('2021-1-1','2021-1-3')
1962 · Query courses with teacher id other than 1 and 3
1
SELECT `name` FROM courses WHERE `teacher_id` NOT IN(1,3)
1964 · Query for course information about the number of students within the specified range
1
SELECT * FROM `courses` WHERE `student_count` BETWEEN 50 AND 55;
1972 · Inquire about Chinese and Japanese teachers who have e-mail addresses
1
SELECT * FROM teachers WHERE (email IS NOT NULL) AND (`country`='CN' OR `country`='JP');
1974 · Query teacher information by email
1
SELECT `name`,`email` FROM `teachers` WHERE `email` LIKE '%@qq.com';
1982 · Check the age of teachers and sort them in ascending order
1
SELECT DISTINCT `age` FROM `teachers` ORDER BY `age`;
1977 · Sorted by age of Chinese teachers in descending order
1
SELECT * FROM `teachers` WHERE `country`='CN' ORDER BY `age` DESC;
1980 · Search for the oldest Chinese teacher
1
SELECT * FROM `teachers` WHERE `country`='CN' ORDER BY `age` DESC LIMIT 1;