Hello SQL
2045 · 输出 Hello LintCode
SELECT “Hello LintCode!”
简单的 SELECT 语句
#2013 · 查询老师的姓名
SELECT name
from teachers;
2007 · 查询课程名称和上课人数
SELECT name
,student_count
FROM courses;
2009 · 查询所有老师
SELECT * from teachers;
1981 · 查询所有教师的国籍
SELECT distinct country from teachers;
2011 · 查询上课人数超过 1000 的课程信息
SELECT * from courses where student_count > 1000;
2012 · 查询课程名为 Artificial Intelligence 的课程信息
SELECT * FROM courses WHERE name=‘Artificial Intelligence’
简单的 INSERT 语句
2017 · 向课程表中插入 SQL 课程信息
insert into courses values(14,‘SQL’,200,‘2021-02-25’,1);
2021 · 向教师表指定的列插入教师信息
insert into teachers
(name
,email
,age
,country
) values (‘XiaoFu’,‘XiaoFu@lintcode.com’,‘20’,‘CN’);
简单的 UPDATE 语句
2020 · 更新选择人工智能的学生人数
update courses
set student_count
= ‘500’
where name
= ‘Artificial Intelligence’;
简单的 DELETE 语句
2004 · 删除 2020 年前的所有课程
DELETE FROM courses
WHERE created_at
< ‘2020-1-1’ ;
2019 · 删除表中所有行
DELETE FROM courses
;
练习链接:https://www.lintcode.com/learn/39/29