- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
HYPERLINK /elleniou/archive/2012/10/24/2736726.html 学习数据库必须掌握的54条SQL查询语句
1 --1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。
2 select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),日期不详) birthday
3 from employee
4 order by dept
5
6 --2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称
7 select emp_no,emp_name,dept,title
8 from employee
9 where emp_name喻自强 and dept in
10 (select dept from employee
11 where emp_name=喻自强)
12
13 --3、按部门进行汇总,统计每个部门的总工资
14 select dept,sum(salary)
15 from employee
16 group by dept
17
18 --4、查找商品名称为14寸显示器商品的销售情况,显示该商品的编号、销售数量、单价和金额
19 select d_id,qty,unit_price,unit_price*qty totprice
20 from sale_item a,product b
21 where d_id=d_id and prod_name=14寸显示器
22
23 --5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额
24 select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
25 from sale_item
26 group by prod_id
27
28 --6、使用convert函数按客户编号统计每个客户1996年的订单总金额
29 select cust_id,sum(tot_amt) totprice
30 from sales
31 where convert(char(4),order_date,120)=1996
32 group by cust_id
33
34 --7、查找有销售记录的客户编号、名称和订单总额
35 select a.cust_id,cust_name,sum(tot_amt) totprice
36 from customer a,sales b
37 where a.cust_id=b.cust_id
38 group by a.cust_id,cust_name
39
40 --8、查找在1997年中有销售记录的客户编号、名称和订单总额
41 select a.cust_id,cust_name,sum(tot_amt) totprice
42 from customer a,sales b
43 where a.cust_id=b.cust_id and convert(char(4),order_date,120)=1997
44 group by a.cust_id,cust_name
45
46 --9、查找一次销售最大的销售记录
47 select order_no,cust_id,sale_id,tot_amt
48 from sales
49 where tot_amt=
50 (select max(tot_amt)
51 from sales)
52
53 --10、查找至少有3次销售的业务员名单和销售日期
54 select emp_name,order_date
55 from employee a,sales b
56 where emp_no=sale_id and a.emp_no in
57 (select sale_id
58 from sales
59 group by sale_id
60 having count(*)=3)
61 order by emp_name
62
63 --11、用存在量词查找没有订货记录的客户名称
64 select cust_name
65 from customer a
66 where not exists
67 (select *
68 from sales b
69 where a.cust_id=b.cust_id)
70
71
文档评论(0)