下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、題目: 現(xiàn)有一個(gè)商店的數(shù)據(jù)庫,記錄顧客及其購物情況,由下面三個(gè)表組成: 商品(商品號(hào),商品名,單價(jià),商品類別,供應(yīng)商); 顧客(顧客號(hào),姓名,住址); 購買(顧客號(hào),商品號(hào),購買數(shù)量); 試用 SQL語言完成下列功能: 1 建表,在定義中要求聲明: (1)每個(gè)表的主外碼; (2)顧客的姓名和商品名不能為空值; (3)單價(jià)必須大于 0,購買數(shù)量必須再 0到 20之間; 2 往表中插入數(shù)據(jù): 商品( M01,佳潔士,牙膏,寶潔; M02,高露潔,牙膏,高露潔; M03,潔諾,牙膏,聯(lián)合利華; M04,舒膚佳,香皂,寶潔; M05,夏士蓮,香皂,聯(lián)合利華; M06,雕牌,洗衣粉,納愛斯 M07,中華
2、,牙膏,聯(lián)合利華; M08,汰漬,洗衣粉,寶潔; M09,碧浪,洗衣粉,寶潔;) 顧客( C01,Dennis,海淀; C02,John,朝陽; C03,Tom,東城; C04,Jenny,東城; C05,Rick ,西城;) 購買 (C01 ,M01, 3; C01,M05, 2; C01, M08, 2; C02, M02,5; C02, M06, 4; C03, M01,1; C03, M05, 1; C03, M06,3; C03, M08, 1; C04, M03,7; C04, M04, 3; C05, M06,2; C05, M07, 8;) 商品有 9 條, 顧客有 5條, 購
3、買有 5 條 3 用 SQL語句完成下列查詢: (1)求購買了供應(yīng)商 寶潔 產(chǎn)品的所有顧客; ( 2)求購買的商品包括了顧客 Dennis 所購買商品的顧客(姓名); (3)求牙膏賣出數(shù)量最多的供應(yīng)商。 4 將所有的牙膏商品單價(jià)增加 10%。 5 刪除從未被購買的商品記錄。 參考答案: create table product ( productno char(10) not null, productname char(15) not null, price float(15), sort char(10), supplier char(20), primary key (productno
4、), check (price 0) ) create table customer ( customerno char(10) not null, customername char(15) not null, address char(10), primary key (customerno) ) create table buy ( customerno char(10) not null, productno char(10) not null, num smallint, primary key (customerno,productno), foreign key (custome
5、rno) references customer (customerno), foreign key (productno) references product (productno), check (num between 0 and 20) insert into product values (M01, insert into product values(M02, insert into product values(M03, insert into product values(M04, insert into product values(M05, insert into pro
6、duct values(M06, insert into product values(M07, insert into product values(M08, insert into product values(M09, 佳潔士 , 牙膏, 寶潔); 高露潔 , 牙膏, 高露潔 ); 潔諾, 牙膏, 聯(lián)合利華 ) ; 舒膚佳, 香皂, 寶潔) ; 夏士蓮, 香皂, 聯(lián)合利華 ); 雕牌, 洗衣粉, 納愛斯 ); 中華, 牙膏, 聯(lián)合利華 ) ; 汰漬, 洗衣粉, 寶潔) ; 碧浪, 洗衣粉, 寶潔) ; insert into customer values (C01,Dennis,海淀
7、) ; insert into customer values(C02,John, 朝陽 ) ; insert into customer values(C03,Tom,東城) ; insert into customer values(C04,Jenny,東城 ); insert into customer values(C05,Rick, 西城 ) ; insert into buy values (C01,M01,3); insert into buy values(C01,M05,2); insert into buy values(C01,M08,2); insert into bu
8、y values(C02,M02,5); insert into buy values(C02,M06,4); insert into buy values(C03,M01,1); insert into buy values(C03,M05,1); insert into buy values(C03,M06,3); insert into buy values(C03,M08,1); insert into buy values(C04,M03,7); insert into buy values(C04,M04,3); insert into buy values(C05,M06,2);
9、 insert into buy values(C05,M07,8); 1)求購買了供應(yīng)商 寶潔 產(chǎn)品的所有顧客; supplier select , from product p,customer c, buy b where = and = and = 寶潔 ( 2)求購買的商品包括了顧客 Dennis 所購買商品的顧客(姓名) ; 參考書本 p126 select distinct from buy as x , customer c where not exists ( select * from buy as y where in (select customerno from cu
10、stomer where customername = Dennis ) and not exists ( select * from buy as z where = and = ) ) and = (3)求牙膏賣出數(shù)量最多的供應(yīng)商。 select ,sum(num) from product p,customer c, buy b where = and = and sort = 牙膏 group by having sum(num) = all ( select sum(num) from product p,customer c, buy b where = and = and sort = 牙膏
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年引導(dǎo)信標(biāo)機(jī)項(xiàng)目資金申請(qǐng)報(bào)告代可行性研究報(bào)告
- 部編版三年級(jí)上冊(cè)語文第2周作業(yè)單
- 北京巿通州區(qū)2024-2025學(xué)年高三3月調(diào)研考試生物試題理試題含解析
- 安徽省黃山市屯溪區(qū)屯溪第一中學(xué)2024-2025學(xué)年高考原創(chuàng)信息試卷生物試題(一)含解析
- 2025年浙江省紹興市高三單科質(zhì)檢生物試題含解析
- 2025年四川南充市高高三下學(xué)期四調(diào)考試生物試題(A4版含解析)含解析
- 2022安全生產(chǎn)法考核試題及答案
- 《個(gè)人衣服我來穿》 教學(xué)設(shè)計(jì) 小學(xué)勞動(dòng)教育
- 膠合板熱熔膠相關(guān)項(xiàng)目創(chuàng)業(yè)計(jì)劃書
- 江西省萬載縣七年級(jí)地理上冊(cè) 2.2眾多的人口教案 中圖版
- 學(xué)習(xí)領(lǐng)悟在全國民族團(tuán)結(jié)進(jìn)步表彰大會(huì)上重要講話心得體會(huì)
- 紅薯種植課程設(shè)計(jì)
- 2024-2025學(xué)年九年級(jí)歷史上學(xué)期第一次月考模擬卷(統(tǒng)編版)
- 2024至2030年中國生物燃料行業(yè)深度調(diào)研及投資戰(zhàn)略分析報(bào)告
- 《我為學(xué)校出點(diǎn)力》(教學(xué)設(shè)計(jì)+學(xué)習(xí)任務(wù)單)-道德與法治2024-2025學(xué)年三年級(jí)上冊(cè)統(tǒng)編版
- 三級(jí)醫(yī)院醫(yī)療服務(wù)能力與質(zhì)量安全監(jiān)測數(shù)據(jù)評(píng)審標(biāo)準(zhǔn)實(shí)施細(xì)則
- 2020-2024年高考地理復(fù)習(xí)試題分類匯編:地質(zhì)地貌(北京專用)(解析版)
- 村級(jí)文化設(shè)施管理制度
- 物資出入庫流程圖(參考模板)
- 醫(yī)學(xué)統(tǒng)計(jì)學(xué)十套題
- (完整版)加固工程技術(shù)標(biāo)
評(píng)論
0/150
提交評(píng)論