Lintcode SQL 教程 LEVEL 2

比较运算符
1952 · 查询超过 20 岁的教师

select * from teachers where age > ‘20’;
1953 · 查询中国老师的姓名

select name from teachers where country = ‘CN’;
逻辑运算符
1957 · 查询2020年5月之前开课的课程

select name,created_at from courses where created_at < ‘2020-05-01’ and created_at >= ‘2020-01-01’;
1958 · 查询指定教师所教授的满足条件的课程

select * from courses where teacher_id = ‘4’ and student_count > ‘500’;
2001 · 查询 ‘Web’ 或 ‘Big Data’ 的课程信息

SELECT * from courses where name = ‘Web’ or name = ‘Big Data’
2040 · 查询教师 id 不为 3 且人数大于 800 的课程

select * from courses where not (teacher_id=‘3’) and student_count>‘800’;
特殊条件
1960 · 查询指定时间的课程信息

select * from courses where created_at in (‘2021-01-01’,‘2021-01-03’);
1962 · 查询教师 id 不为 1 和 3 的课程

select name from courses where teacher_id not in (‘1’,‘3’);
1964 · 查询学生数量在指定范围内的课程信息

select * from courses where student_count between ‘50’ and ‘55’;
1972 · 查询有电子邮箱的中日籍教师

select * from teachers where country in (‘JP’,‘CN’) AND email IS NOT NULL;
1974 · 根据邮箱查询教师信息

select name,email from teachers where email LIKE ‘%@qq.com’;
ORDER BY 与 LIMIT
1982 · 查询教师的年龄并按升序排序

select distinct age from teachers order by age;
1977 · 根据中国教师年龄降序排序

select * from teachers where country = ‘CN’ ORDER BY ‘age’ DESC;
1980 · 查询年龄最大的中国教师

select * from teachers where country = ‘CN’ order by age desc limit 1 ;

https://www.nues.cn/index.php/archives/198/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值