10-7 3-2-(b)查询由生产厂商B生产的所有产品的型号(model) 和价格(price) (10 分)

1.查询由生产厂商B生产的所有产品的型号(model) 和价格(price) (10 分)

-- 查询由生产厂商B生产的所有产品的型号(model) 和价格(price)。 
-- 提示:查询按照pc、laptop和printer的顺序进行。
-- union:是连接多个查询的语句
--   还有就是这里的 in ()  括号中不可添加为('1006','3002')

select model,price from pc
    where model in (select model from product where maker = 'B')
union   
select model,price from laptop
    where model in (select model from product where maker = 'B')
union    
select model,price from printer
    where model in (select model from product where maker = 'B')
    

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

-- 查询所有出售便携式电脑(而不出售PC机)的生产厂商。
-- 解释:个人电脑也就是pc机 laptop是便携式电脑

-- 分析:1.求出所有出售便携式电脑的厂商  (d,e)
--      2.求出所有出售pc机的厂商(a,d)
--      3.找出(d,e)不在(a,d)当中的当中的厂商

-- -- 便携式
select DISTINCT product.maker from laptop,product
            where laptop.model = product.model
            and product.maker not in (select maker from pc,product
                                where pc.model = product.model);

3:查询在两种或两种以上PC机上出现的硬盘容量 (10 分)

-- 查询在两种或两种以上PC机上出现的硬盘容量。

-- 分析:1.先按硬盘容量进行分组
--      2.在将其作为子表

-- select hd,count(*) from pc
--     group by hd;
    
select temp.hd
    from (select hd,count(*) as num from pc
            group by hd) temp
    where temp.num >= 2;
    

4:查询拥有相同速度和内存的PC机的成对的型号 (10 分)

select temp1.model as model1,temp2.model as model2
    from pc temp1,pc temp2
    where temp1.speed = temp2.speed
    and temp1.ram = temp2.ram
    and temp1.model < temp2.model

5. 查询电影“M3”中的男影星 (10 分)

-- 多表查询  条件是 演员的姓名进行联系两个表
--   然后就是 演员表当中性别为男

-- select name
--      from StarsIn,MovieStar
--      where starName = name
--      and gender = 'M'
--      and movieTile = 'M3';


--  用到了多行子查讯
-- select starName from MovieStar
--     where movieTile = 'M3';
    
select name
     from MovieStar
     where name in (select starName from StarsIn
                        where movieTitle = 'M3')
     and gender = 'M';                 

6:查询st1制片公司的总裁 (10 分)

select MovieExec.name
      from MovieExec,Studio
      where certID = presCertID
      and Studio.name = 'st1';

7:`查询在st1公司于2018年制作的电影中出演的影星 (10 分)

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

-- 分析:1.查询st1公司2018年制作了哪些电影在movie表当中
--      2.然后在将其上方的查询结果作为子查询 在StarsIn表中

-- select title from Movie
--     where studioName = 'st1'
--     and year = 2018;
    

SELECT  DISTINCT starName
        FROM StarsIn
        WHERE movieTitle IN (SELECT title FROM Movie
                            WHERE studioName = 'st1'
                              AND YEAR = 2018)	
        and movieYear = 2018;

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

天天向上的菜鸡杰!!

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

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

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

打赏作者

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

抵扣说明:

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

余额充值