SQL经典查询语句精选doc

SQL经典查询语句精选doc

ID:42671529

大小:70.00 KB

页数:9页

时间:2019-09-19

SQL经典查询语句精选doc_第1页
SQL经典查询语句精选doc_第2页
SQL经典查询语句精选doc_第3页
SQL经典查询语句精选doc_第4页
SQL经典查询语句精选doc_第5页
资源描述:

《SQL经典查询语句精选doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、--1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,--显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。selectemp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'日期不详')birthdayfromemployeeorderbydept--2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称selectemp_no,emp_name,dept,titlefromemployeewhereemp_name<>'喻自强'anddeptin(s

2、electdeptfromemployeewhereemp_name='喻自强')--3、按部门进行汇总,统计每个部门的总工资selectdept,sum(salary)fromemployeegroupbydept--4、查找商品名称为14寸显示器商品的销售情况,--显示该商品的编号、销售数量、单价和金额selecta.prod_id,qty,unit_price,unit_price*qtytotpricefromsale_itema,productbwherea.prod_id=b.prod_idandprod_name='14寸显示器'

3、--5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额selectprod_id,sum(qty)totqty,sum(qty*unit_price)totpricefromsale_itemgroupbyprod_id--6、使用convert函数按客户编号统计每个客户1996年的订单总金额selectcust_id,sum(tot_amt)totpricefromsaleswhereconvert(char(4),order_date,120)='1996'groupbycust_id--7、查找有销售记录的客户编号、名称和

4、订单总额selecta.cust_id,cust_name,sum(tot_amt)totpricefromcustomera,salesbwherea.cust_id=b.cust_idgroupbya.cust_id,cust_name--8、查找在1997年中有销售记录的客户编号、名称和订单总额selecta.cust_id,cust_name,sum(tot_amt)totprice-9-fromcustomera,salesbwherea.cust_id=b.cust_idandconvert(char(4),order_date,1

5、20)='1997'groupbya.cust_id,cust_name--9、查找一次销售最大的销售记录selectorder_no,cust_id,sale_id,tot_amtfromsaleswheretot_amt=(selectmax(tot_amt)fromsales)--10、查找至少有3次销售的业务员名单和销售日期selectemp_name,order_datefromemployeea,salesbwhereemp_no=sale_idanda.emp_noin(selectsale_idfromsalesgroupbys

6、ale_idhavingcount(*)>=3)orderbyemp_name--11、用存在量词查找没有订货记录的客户名称selectcust_namefromcustomerawherenotexists(select*fromsalesbwherea.cust_id=b.cust_id)--12、使用左外连接查找每个客户的客户编号、名称、订货日期、订单金额--订货日期不要显示时间,日期格式为yyyy-mm-dd--按客户编号排序,同一客户再按订单降序排序输出selecta.cust_id,cust_name,convert(char(10

7、),order_date,120),tot_amtfromcustomeraleftouterjoinsalesbona.cust_id=b.cust_idorderbya.cust_id,tot_amtdesc--13、查找16MDRAM的销售情况,要求显示相应的销售员的姓名、--性别,销售日期、销售数量和金额,其中性别用男、女表示selectemp_name姓名,性别=casea.sexwhen'm'then'男'when'f'then'女'else'未'end,销售日期=isnull(convert(char(10),c.order_da

8、te,120),'日期不详'),qty数量,qty*unit_priceas金额-9-fromemployeea,salesb,sale_itemc,

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。