1445.苹果和橘子
题目分析:题目要求求出苹果和橘子之间的差,那么只需要单独求出苹果和橘子的数量,然后inner join后相减即可
先筛选苹果的数目
select sale_date,fruit apples,sold_num from Sales where fruit LIKE 'apples'
然后筛选橘子的数目
select sale_date,fruit oranges,sold_num from Sales where fruit LIKE 'oranges'
对结果进行inner join后对两个数目进行相减
select A.sale_date,a_sold_num-o_sold_num diff from (
select sale_date,fruit apples,sold_num a_sold_num from Sales where fruit LIKE 'apples') A inner join (
select sale_date,fruit oranges,sold_num o_sold_num from Sales where fruit LIKE 'oranges') O on A.sale_date = O.sale_date order by sale_date
提交结果如下: