SQL实验

发布时间:   来源:文档文库   
字号:
SQL实验6
SQL2009-05-1721:56:02阅读50评论0字号:大中小订阅
--1.sales中的平均销售数量(列别名为Qty_Avg
selectavg(qtyas'Qty_Avg'fromsales
--2.Sales中总共有多少笔销售记录(列别名为Total_Trans
selectcount(ord_numas'Total_Trans'fromsales--3.Sales中总图书销量(结果列别名为Total_Qty
selectsum(qtyas'Total_Qty'fromsales
--4.sales中销量最大的一笔记录的销量(结果列别名为Max_Qty
selectmax(qtyas'Max_Qty'fromsales
--5.sales中销量最小的一笔记录的销量(结果列别名为Min_Qty
selectmin(qtyas'Min_Qty'fromsales
--6.sales中每一种图书的总销量(列别名为Total_Qty_PerBook和它对应的标题号(Title_ID
selecttitle_id,sum(qtyas'Total_Qty_PerBook'fromsalesgroupbytitle_id
--7.sales中每天图书的总销量(列别名为Total_Qty_Perday和它对应的日期(ORD_DATE
selectord_date,sum(qtyas'Total_Qty_Perday'fromsalesgroupbyord_date
--8.sales中日期为1994-9-5之后每天图书的总销量(列别名为Total_Qty_Perday和它对应的日期
(Ord_Date
selectord_date,sum(qtyas'Total_Qty_Perday'fromsalesgroupbyord_datehaving
ord_date>'1994-9-5'
--9.sales中每笔记录的销量和它对应的书名(Title
selectsales.ord_num,titles.titlefromsalesjointitlesonsales.title_id=titles.title_id
--10.sales中每笔记录的销量、对应的书名(Title和商店名称(Stor_Name
selectsales.ord_num,titles.title,stores.stor_namefromsalesjointitlesonsales.title_id=titles.title_idJOIN
storesonsales.stor_id=stores.stor_id
--11.sales中所在的州为加利福尼亚州(‟CA‟)的那些商店的名称和销量记录.注:要求使用IN关键字查

selectstores.stor_name,sales.qtyfromstoresjoinsalesonstores.stor_id=stores.stor_idwhere
stores.statein('CA'groupbystores.stor_name,sales.qty
--12.Sales中销量大于平均销量的销售记录
select*fromsaleswhereqty>(selectavg(qtyfromsales

--13.Authors中与作者au_lname‟Stringer‟,au_fname‟Dirk‟所在城市相同的作者的信息
select*fromauthorswherecityin(selectcityfromauthorswhereau_lnamelike'Stringer'andau_fname
like'Dirk'


--14.Authors中与作者au_lname‟Stringer‟,au_fname‟Dirk‟所在的城市不同的作者的信息select*fromauthorswherecitynotin(selectcityfromauthorswhereau_lnamelike'Stringer'and
au_fnamelike'Dirk'
--15.使用titles表创建视图VBusiness,包含以下列:title_id,titletype,条件是type„business‟
createviewVBusinessasselecttitle_id,title,typefromtitleswheretype='business'
--16.使用titleauthor表和authors表创建视图VTitleAuthor包含以下列authors表中的au_idau_lname
au_fname合并的姓名,titleauthor表中的title_id
createviewVTitleAuthorasselectauthors.au_id,rtrim(authors.au_lname+authors.au_fnameas'full
name',titleauthor.title_idfromauthorsjointitleauthorontitleauthor.au_id=authors.au_id
--17.删除视图VBusinessdropviewVBusiness



本文来源:https://www.2haoxitong.net/k/doc/c6be1d4a852458fb770b566a.html

《SQL实验.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式