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
本题目要求编写SELECT语句,在SPJ数据库中,列出各个供应商供应各种零件的数量合计的汇总列表。
要求:显示出每个供应商供应每种零件的数量合计和每个供应商供应所有零件的数量合计以及所有供应商供应的所有零件数量合计。
提示:请使用 " WITH ROLLUP " 语句作答。
select coalesce(sno,'所有供应商') as 供应商,coalesce(pno,'所有零件') as 零件,sum(qty) as 供应量
from spj
group by sno,pno
with rollup;
本题目要求编写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
)
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))
查询所有出售便携式电脑(而不出售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
);
查询在st1公司于2018年制作的电影中出演的影星。
select distinct starName
from StarsIn,Movie
where StarsIn.movieTitle=Movie.title and StarsIn.movieYear=Movie.year and year=2018 and studioName='st1';
检索出MovieStar表中所有的男影星或者住址中含有4的影星
select distinct name
from MovieStar
where gender='M' or address like '%4'