HW # 2 answers -.doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
HW # 2 answers -.doc

HW # 2 answers - 1) List name and city of all customers. (Coffee: Projection) Select cname, city from customers; 2) List products in descending order by price (Coffee: SQL - JavaApplets - Constructing SQL Queries advance - Order By) Select * from products order by price desc; 3) List customers that ordered ‘p01’ or ‘p02’ (Coffee: Restriction) Select cid from orders where pid = ‘p01’ or pid = ‘p02’ 4) List customers that ordered ‘p01’ and ‘p02’ (Need to use INTERSECT or 2 Virtual tables of ORDERS). Select * from customers where cid in (select cid from orders where pid = ‘p01’) And cid in (select cid from orders where pid = ‘p02’); 5) List the name of each agent and the sum of orders (in dollars) that each agent ordered (Coffee: SQL - JavaApplets - Constructing SQL Queries advance - Functions and Group BY) select a.aname, sum (dollars) Dollars from agents a, orders o where a.aid = o.aid group by a.aname; 6) Insert a new row in customers with cid = ‘c007’, ‘Coke’, ‘Atlanta’, 7 (Coffee: SQL - JavaApplets - Data Definition Language and Data Manipulation Language) Insert into customers (cid, cname, city, discnt) values (‘c007’, ‘Coke’, ‘Atlanta’, ‘7.00’); 7) List the name each customers and the total amount ordered by the customers If the customers didn’t place an order, list them also. Select c.cname, sum (o.dollars) Dollars From customers c, orders o Where c.cid = o.cid (+) Group by cname; 8) List name of customers that ordered all the products. Select cname from customers c where not exists (Select * from products p where not exists (select * from orders o where o.cid = c.cid and o.pid = p.pid)); 9) List all pair of products that are in the same city (Coffee: SQL - More SQL (Visual Basic) - Join with 1 table Select p1.pid, p2.pid From products p1, products p2 Where p1.pid p2.pid and p1.city = p2.city; List the three most expensive products (one sql statement. Warning: HARD. Use NOT EXISTS) Select *

文档评论(0)

seym + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档