组队学习-sql-20220616

本文详细解析了SQL查询的基本操作,包括按日期筛选、空值判断、价格比较、复杂运算与分组聚合,涵盖了从基础到进阶的查询技巧。通过实例展示了如何使用WHERE, NOT, AND, OR等进行条件设置,并探讨了GROUP BY和HAVING的用法。
摘要由CSDN通过智能技术生成

简单查询

作业1:按照条件查询

select product_name
      ,regist_date
  from product
 where regist_date > date'20090428';

查询结果:
在这里插入图片描述

作业二:获取sql语句结果

select *
from product
where purchase_price = NULL;
-- 返回结果:无结果
select *
from product
where purchase_price <> NULL;
-- 返回结果:无结果
select *
from product
where purchase_price > NULL;
-- 返回结果:无结果

作业三:根据要求查询

select product_name
      ,sale_price
      ,purchase_price
from product
where (sale_price - purchase_price) >= 500;
--另一种写法
select product_name
      ,sale_price
      ,purchase_price
from product
where NOT (sale_price - purchase_price) < 500;

作业四:根据要求查询

select product_name  
      ,product_type
      ,(sale_price * 0.9 - purchase_price) as profit
from product
where (sale_price * 0.9 - purchase_price) > 100;

查询结果:
在这里插入图片描述

作业五:指出错误

where语句应该在group by语句前面。

作业六:根据要求查询

select product_type
      ,sum(sale_price)
      ,sum(purchase_price)
from product
group by product_type
having sum(sale_price) > sum(purchase_price)*1.5;

作业七:根据结果猜测order by语句

select *
from product
order by - regist_date, purchase_price;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值