简单查询
作业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;