一、查询
1.可回收且低脂的产品
题目描述
代码编写
SELECT p.product_id FROM Products
SELECT product_id
FROM Products
WHERE low_fats = 'Y' AND recyclable = 'Y'
2.寻找用户推荐人
题目描述
代码编写
做法一(用时606ms)
select name from Customer
where referee_id !=2 or referee_id is null
做法二(用时626ms)
select name from Customer
where not referee_id <=>2
Tip:运算符<=>
<=>为null安全的等值比较符号,作用类似于 ' = ',结合了 ‘ = ’运算符和 Is 关键字的作用,既能判断具体数值,也能判断非空,上述代码中的<=>2筛选选项的是等于2的非空值。
做法三(用时482ms)
select name from Customer
where id not in (select id from Customer where referee_id=2)
3.大的国家
题目描述
代码编写
select name,population,area from world
where area>=3000000 or population>=25000000
4.文章浏览
题目描述
代码编写
select distinct(author_id) as id from views
where author_id=viewer_id
order by id asc
5.无效的推文
题目描述
代码编写
select tweet_id from tweets
where length(content)>15