10-3 B1-5查询客户的订单情况

查找客户的订单情况,显示为:顾客编号(CustomerID) ,公司名称(CompanyName),订单编号(OrderID),员工编号(EmployeeID)


select customers.CustomerID,customers.CompanyName,orders.OrderID,orders.EmployeeID
from customers,orders
where orders.CustomerID=customers.CustomerID  and  orders.ShipCity=customers.City
order by customers.CustomerID ASC

查询选修某两门课程的学生

本题目要求编写SQL语句, 检索出sc表中至少选修了’C001’与’C002’课程的学生学号

select a.sno '学号' 
from (select * from sc where (cno = 'C001')) a 
inner join 
(select * from sc where (cno = 'C002')) b 
on a.sno = b.sno

spj-显示供应商供应零件的汇总列表

本题目要求编写SELECT语句,在SPJ数据库中,列出各个供应商供应各种零件的数量合计的汇总列表。
要求:显示出每个供应商供应每种零件的数量合计和每个供应商供应所有零件的数量合计以及所有供应商供应的所有零件数量合计。
提示:请使用 " WITH ROLLUP " 语句作答。

select coalesce(sno,'所有供应商') as 供应商,coalesce(pno,'所有零件') as 零件,sum(qty) as 供应量
from spj
group by sno,pno
with rollup;

5-3 查询生产最高速度的计算机(PC或便携式电脑)厂商

本题目要求编写SQL语句, 查询生产最高速度的计算机(PC或便携式电脑)厂商,查询结果按照厂商升序排列

select distinct maker
from (
	select maker,speed
  from pc,product
  where pc.model=product.model
  union
  select maker,speed
  from laptop,product
  where laptop.model=product.model
) a
where a.speed in (
	select max(speed)
  from (
  	select speed
    from pc,product
    where pc.model=product.model
    union
    select speed
    from laptop,product
    where laptop.model=product.model
  ) b
);

查询价格最高的打印机型号

查询价格最高的打印机型号。

select distinct model
from printer 
where price >= all (
    select price 
    from printer
)

A2-2查找产品表中再次订购量大于等于10且修订量大于订货数量的产品信息

select ProductID,ProductName,SupplierID
from products
where ReorderLevel> UnitsOnOrder and ReorderLevel>=10

查询平均成绩以上的课程

查询每个同学超过他选修的平均成绩的课程。

select sno 学号,cname 课程名,grade 成绩
from cou,sc a 
where cou.cno = a.cno and 
(a.grade > (select avg(b.grade) from sc b where a.sno = b.sno))

3-2-©查询所有出售便携式电脑(而不出售PC机)的生产厂商

查询所有出售便携式电脑(而不出售PC机)的生产厂商。

select distinct maker
from product,laptop
where product.model=laptop.model and maker not in (
    select maker
    from product,pc
    where product.model=pc.model 

);

3-1-©查询在st1公司于2018年制作的电影中出演的影星

查询在st1公司于2018年制作的电影中出演的影星。


select distinct starName
from StarsIn,Movie
where StarsIn.movieTitle=Movie.title and StarsIn.movieYear=Movie.year and year=2018 and studioName='st1';

2-1-(e) 查询所有的男影星或者住址中含有4的影星

检索出MovieStar表中所有的男影星或者住址中含有4的影星

select distinct name
from MovieStar
where gender='M' or address like '%4'
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇灬宇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值