select Products.product_id from Products where low_fats = 'Y' and recyclable = 'Y';
朴实无华的语句薄纱了
这题我先输入一个!=2,发现有null过不了
再加入一个= null,发现还是没用,看了一下,null 使用的话,得用is null;....
select name,population,area
from World
where area >=3000000 or population >= 25000000;
select distinct author_id as 'id' from Views where author_id = viewer_id order by author_id ASC;
根据题目要求,要去重用distinct,还得排序,order by 排序条件 asc;默认升序asc排序,desc降序排序
select tweet_id from tweets where char_length(content)>15;
char_length(str)获取字符串长度的函数
select e2.unique_id,e1.name from employees e1 left join EmployeeUNI e2 on e1.id = e2.id;
两张表进行拼接,我们使用多表查询里面的左连接来完成,左连接包括左表和左表与右表有交集的部分,题目两张表共有部分是id,并且unique_id有的人是没有的,使用我们让第一张表左连接第二张表,对于没有unique_id的我们默认用null填充
select product_name,year,price from sales,product where sales.product_id = product.product_id;
解释: ID = 23 的顾客曾经逛过一次购物中心,并在 ID = 12 的访问期间进行了一笔交易。 ID = 9 的顾客曾经逛过一次购物中心,并在 ID = 13 的访问期间进行了一笔交易。 ID = 30 的顾客曾经去过购物中心,并且没有进行任何交易。 ID = 54 的顾客三度造访了购物中心。在 2 次访问中,他们没有进行任何交易,在 1 次访问中,他们进行了 3 次交易。 ID = 96 的顾客曾经去过购物中心,并且没有进行任何交易。 如我们所见,ID 为 30 和 96 的顾客一次没有进行任何交易就去了购物中心。顾客 54 也两次访问了购物中心并且没有进行任何交易。
首先先看出两张表的关联部分就是visit_id
可以看出visit_id为4,6,7,8的客人没有进行消费
我们就得找出这些客人的信息,发现customer_id为54的客人来过三次,但是只消费了一次
我们就得把消费的次数记录下来
通过visit_id 结合两张表
找到没有进行交易的人,也就是transaction中名为visit_id不存在的
再把他们用group by组成一个组用count算出没消费的次数
select customer_id,count(customer_id) as count_no_trans
from Visits left join Transactions
on visits.visit_id=Transactions.visit_id
where Transactions.visit_id is null
group by customer_id;