人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

實(shí)例學(xué)習(xí)SQL的Select命令

發(fā)布日期:2022-02-04 16:22 | 文章來源:gibhub

--顯示日期不詳,并按部門排序輸出,日期格式為yyyy-mm-dd。
selectemp_no,emp_name,dept,
isnull(convert(char(10),birthday,120),'日期不詳')birthday
fromemployee
orderbydept --2、查找與喻自強(qiáng)在同一個(gè)單位的員工姓名、性別、部門和職稱
selectemp_no,emp_name,dept,title
fromemployee
whereemp_name<>'喻自強(qiáng)'anddeptin
(selectdeptfromemployee
whereemp_name='喻自強(qiáng)') --3、按部門進(jìn)行匯總,統(tǒng)計(jì)每個(gè)部門的總工資
selectdept,sum(salary)
fromemployee
groupbydept --4、查找商品名稱為14寸顯示器商品的銷售情況,
--顯示該商品的編號(hào)、銷售數(shù)量、單價(jià)和金額
selecta.prod_id,qty,unit_price,unit_price*qtytotprice
fromsale_itema,productb
wherea.prod_id=b.prod_idandprod_name='14寸顯示器' --5、在銷售明細(xì)表中按產(chǎn)品編號(hào)進(jìn)行匯總,統(tǒng)計(jì)每種產(chǎn)品的銷售數(shù)量和金額
selectprod_id,sum(qty)totqty,sum(qty*unit_price)totprice
fromsale_item
groupbyprod_id --6、使用convert函數(shù)按客戶編號(hào)統(tǒng)計(jì)每個(gè)客戶1996年的訂單總金額
selectcust_id,sum(tot_amt)totprice
fromsales
whereconvert(char(4),order_date,120)='1996'
groupbycust_id --7、查找有銷售記錄的客戶編號(hào)、名稱和訂單總額
selecta.cust_id,cust_name,sum(tot_amt)totprice
fromcustomera,salesb
wherea.cust_id=b.cust_id
groupbya.cust_id,cust_name --8、查找在1997年中有銷售記錄的客戶編號(hào)、名稱和訂單總額
selecta.cust_id,cust_name,sum(tot_amt)totprice
fromcustomera,salesb
wherea.cust_id=b.cust_idandconvert(char(4),order_date,120)='1997'
groupbya.cust_id,cust_name --9、查找一次銷售最大的銷售記錄
selectorder_no,cust_id,sale_id,tot_amt
fromsales
wheretot_amt=
(selectmax(tot_amt)
fromsales) --10、查找至少有3次銷售的業(yè)務(wù)員名單和銷售日期
selectemp_name,order_date
fromemployeea,salesb
whereemp_no=sale_idanda.emp_noin
(selectsale_id
fromsales
groupbysale_id
havingcount(*)>=3)
orderbyemp_name --11、用存在量詞查找沒有訂貨記錄的客戶名稱
selectcust_name
fromcustomera
wherenotexists
(select*
fromsalesb
wherea.cust_id=b.cust_id) --12、使用左外連接查找每個(gè)客戶的客戶編號(hào)、名稱、訂貨日期、訂單金額
--訂貨日期不要顯示時(shí)間,日期格式為yyyy-mm-dd
--按客戶編號(hào)排序,同一客戶再按訂單降序排序輸出
selecta.cust_id,cust_name,convert(char(10),order_date,120),tot_amt
fromcustomeraleftouterjoinsalesbona.cust_id=b.cust_id
orderbya.cust_id,tot_amtdesc --13、查找16MDRAM的銷售情況,要求顯示相應(yīng)的銷售員的姓名、
--性別,銷售日期、銷售數(shù)量和金額,其中性別用男、女表示
selectemp_name姓名,性別=casea.sexwhen'm'then'男'
when'f'then'女'
else'未'
end,
銷售日期=isnull(convert(char(10),c.order_date,120),'日期不詳'),
qty數(shù)量,qty*unit_priceas金額
fromemployeea,salesb,sale_itemc,productd
whered.prod_name='16MDRAM'andd.prod_id=c.prod_idand
a.emp_no=b.sale_idandb.order_no=c.order_no --14、查找每個(gè)人的銷售記錄,要求顯示銷售員的編號(hào)、姓名、性別、
--產(chǎn)品名稱、數(shù)量、單價(jià)、金額和銷售日期
selectemp_no編號(hào),emp_name姓名,性別=casea.sexwhen'm'then'男'
when'f'then'女'
else'未'
end,
prod_name產(chǎn)品名稱,銷售日期=isnull(convert(char(10),c.order_date,120),'日期不詳'),
qty數(shù)量,qty*unit_priceas金額
fromemployeealeftouterjoinsalesbona.emp_no=b.sale_id,sale_itemc,productd
whered.prod_id=c.prod_idandb.order_no=c.order_no --15、查找銷售金額最大的客戶名稱和總貨款
selectcust_name,d.cust_sum
fromcustomera,
(selectcust_id,cust_sum
from(selectcust_id,sum(tot_amt)ascust_sum
fromsales
groupbycust_id)b
whereb.cust_sum=
(selectmax(cust_sum)
from(selectcust_id,sum(tot_amt)ascust_sum
fromsales
groupbycust_id)c)
)d
wherea.cust_id=d.cust_id --16、查找銷售總額少于1000元的銷售員編號(hào)、姓名和銷售額
selectemp_no,emp_name,d.sale_sum
fromemployeea,
(selectsale_id,sale_sum
from(selectsale_id,sum(tot_amt)assale_sum
fromsales
groupbysale_id)b
whereb.sale_sum<1000
)d
wherea.emp_no=d.sale_id --17、查找至少銷售了3種商品的客戶編號(hào)、客戶名稱、商品編號(hào)、商品名稱、數(shù)量和金額
selecta.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price
fromcustomera,productb,salesc,sale_itemd
wherea.cust_id=c.cust_idandd.prod_id=b.prod_idand
c.order_no=d.order_noanda.cust_idin(
selectcust_id
from(selectcust_id,count(distinctprod_id)prodid
from(selectcust_id,prod_id
fromsalese,sale_itemf
wheree.order_no=f.order_no)g
groupbycust_id
havingcount(distinctprod_id)>=3)h) --18、查找至少與世界技術(shù)開發(fā)公司銷售相同的客戶編號(hào)、名稱和商品編號(hào)、商品名稱、數(shù)量和金額
selecta.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price
fromcustomera,productb,salesc,sale_itemd
wherea.cust_id=c.cust_idandd.prod_id=b.prod_idand
c.order_no=d.order_noandnotexists
(selectf.*
fromcustomerx,salese,sale_itemf
wherecust_name='世界技術(shù)開發(fā)公司'andx.cust_id=e.cust_idand
e.order_no=f.order_noandnotexists
(selectg.*
fromsale_itemg,salesh
whereg.prod_id=f.prod_idandg.order_no=h.order_noand
h.cust_id=a.cust_id)
) 19、查找表中所有姓劉的職工的工號(hào),部門,薪水
selectemp_no,emp_name,dept,salary
fromemployee
whereemp_namelike'劉%' 20、查找所有定單金額高于2000的所有客戶編號(hào)
selectcust_id
fromsales
wheretot_amt>2000 21、統(tǒng)計(jì)表中員工的薪水在4000-6000之間的人數(shù)
selectcount(*)as人數(shù)
fromemployee
wheresalarybetween4000and6000 22、查詢表中的同一部門的職工的平均工資,但只查詢"住址"是"上海市"的員工
selectavg(salary)avg_sal,dept
fromemployee
whereaddrlike'上海市%'
groupbydept 23、將表中住址為"上海市"的員工住址改為"北京市"
updateemployee
setaddrlike'北京市'
whereaddrlike'上海市' 24、查找業(yè)務(wù)部或會(huì)計(jì)部的女員工的基本信息。
selectemp_no,emp_name,dept
fromemployee
wheresex='F'anddeptin('業(yè)務(wù)','會(huì)計(jì)') 25、顯示每種產(chǎn)品的銷售金額總和,并依銷售金額由大到小輸出。
selectprod_id,sum(qty*unit_price)
fromsale_item
groupbyprod_id
orderbysum(qty*unit_price)desc 26、選取編號(hào)界于'C0001'和'C0004'的客戶編號(hào)、客戶名稱、客戶地址。
selectCUST_ID,cust_name,addr
fromcustomer
wherecust_idbetween'C0001'AND'C0004' 27、計(jì)算出一共銷售了幾種產(chǎn)品。
selectcount(distinctprod_id)as'共銷售產(chǎn)品數(shù)'
fromsale_item 28、將業(yè)務(wù)部員工的薪水上調(diào)3%。
updateemployee
setsalary=salary*1.03
wheredept='業(yè)務(wù)' 29、由employee表中查找出薪水最低的員工信息。
select*
fromemployee
wheresalary=
(selectmin(salary)
fromemployee) 30、使用join查詢客戶姓名為"客戶丙"所購貨物的"客戶名稱","定單金額","定貨日期","電話號(hào)碼"
selecta.cust_id,b.tot_amt,b.order_date,a.tel_no
fromcustomerajoinsalesb
ona.cust_id=b.cust_idandcust_namelike'客戶丙' 31、由sales表中查找出訂單金額大于"E0013業(yè)務(wù)員在1996/10/15這天所接每一張訂單的金額"的所有訂單。
select*
fromsales
wheretot_amt>all
(selecttot_amt
fromsales
wheresale_id='E0013'andorder_date='1996/10/15')
orderbytot_amt 32、計(jì)算'P0001'產(chǎn)品的平均銷售單價(jià)
selectavg(unit_price)
fromsale_item
whereprod_id='P0001' 33、找出公司女員工所接的定單
selectsale_id,tot_amt
fromsales
wheresale_idin
(selectsale_idfromemployee
wheresex='F') 34、找出同一天進(jìn)入公司服務(wù)的員工
selecta.emp_no,a.emp_name,a.date_hired
fromemployeea
joinemployeeb
on(a.emp_no!=b.emp_noanda.date_hired=b.date_hired)
orderbya.date_hired 35、找出目前業(yè)績超過232000元的員工編號(hào)和姓名。
selectemp_no,emp_name
fromemployee
whereemp_noin
(selectsale_id
fromsales
groupbysale_id
havingsum(tot_amt)<232000) 36、查詢出employee表中所有女職工的平均工資和住址在"上海市"的所有女職工的平均工資
selectavg(salary)
fromemployee
wheresexlike'f'
union
selectavg(salary)
fromemployee
wheresexlike'f'andaddrlike'上海市%' 37、在employee表中查詢薪水超過員工平均薪水的員工信息。
Select*
fromemployee
wheresalary>(selectavg(salary)
fromemployee) 38、找出目前銷售業(yè)績超過10000元的業(yè)務(wù)員編號(hào)及銷售業(yè)績,并按銷售業(yè)績從大到小排序。
Selectsale_id,sum(tot_amt)
fromsales
groupbysale_id
havingsum(tot_amt)>10000
orderbysum(tot_amt)desc 39、找出公司男業(yè)務(wù)員所接且訂單金額超過2000元的訂單號(hào)及訂單金額。
Selectorder_no,tot_amt
Fromsales,employee
Wheresale_id=emp_noandsex='M'andtot_amt>2000 40、查詢sales表中訂單金額最高的訂單號(hào)及訂單金額。
Selectorder_no,tot_amtfromsales
wheretot_amt=(selectmax(tot_amt)fromsales) 41、查詢?cè)诿繌堄唵沃杏嗁徑痤~超過4000元的客戶名及其地址。
Selectcust_name,addrfromcustomera,salesb
wherea.cust_id=b.cust_idandtot_amt>4000 42、求出每位客戶的總訂購金額,顯示出客戶號(hào)及總訂購金額,并按總訂購金額降序排列。
Selectcust_id,sum(tot_amt)fromsales
Groupbycust_id
orderbysum(tot_amt)desc 43、求每位客戶訂購的每種產(chǎn)品的總數(shù)量及平均單價(jià),并按客戶號(hào),產(chǎn)品號(hào)從小到大排列。
Selectcust_id,prod_id,sum(qty),sum(qty*unit_price)/sum(qty)
Fromsalesa,sale_itemb
Wherea.order_no=b.order_no
Groupbycust_id,prod_id
orderbycust_id,prod_id 44、查詢訂購了三種以上產(chǎn)品的訂單號(hào)。
Selectorder_no
fromsale_item
Groupbyorder_no
Havingcount(*)>3 45、查詢訂購的產(chǎn)品至少包含了訂單3號(hào)中所訂購產(chǎn)品的訂單。
Selectdistinctorder_no
Fromsale_itema
Whereorder_no<>'3'andnotexists(
Select*fromsale_itembwhereorder_no='3'andnotexists
(select*fromsale_itemcwherec.order_no=a.order_noandc.prod_id=b.prod_id)) 46、在sales表中查找出訂單金額大于"E0013業(yè)務(wù)員在1996/11/10這天所接每一張訂單的金額"的所有訂單,并顯示承接這些訂單的業(yè)務(wù)員和該訂單的金額。
Selectsale_id,tot_amtfromsales
wheretot_amt>all(selecttot_amt
fromsales
wheresale_id='E0013'andorder_date='1996-11-10') 47、查詢末承接業(yè)務(wù)的員工的信息。
Select*
Fromemployeea
Wherenotexists
(select*fromsalesbwherea.emp_no=b.sale_id) 48、查詢來自上海市的客戶的姓名,電話、訂單號(hào)及訂單金額。
Selectcust_name,tel_no,order_no,tot_amt
Fromcustomera,salesb
Wherea.cust_id=b.cust_idandaddr='上海市' 49、查詢每位業(yè)務(wù)員各個(gè)月的業(yè)績,并按業(yè)務(wù)員編號(hào)、月份降序排序。
Selectsale_id,month(order_date),sum(tot_amt)
fromsales
groupbysale_id,month(order_date)
orderbysale_id,month(order_date)desc 50、求每種產(chǎn)品的總銷售數(shù)量及總銷售金額,要求顯示出產(chǎn)品編號(hào)、產(chǎn)品名稱,總數(shù)量及總金額,并按產(chǎn)品號(hào)從小到大排列。
Selecta.prod_id,prod_name,sum(qty),sum(qty*unit_price)
Fromsale_itema,productb
Wherea.prod_id=b.prod_id
Groupbya.prod_id,prod_name
orderbya.prod_id
51、查詢總訂購金額超過'C0002'客戶的總訂購金額的客戶號(hào),客戶名及其住址。
Selectcust_id,cust_name,addr
Fromcustomer
Wherecust_idin(selectcust_idfromsales
Groupbycust_id
Havingsum(tot_amt)>
(Selectsum(tot_amt)fromsaleswherecust_id='C0002')) 52、查詢業(yè)績最好的的業(yè)務(wù)員號(hào)、業(yè)務(wù)員名及其總銷售金額。
selectemp_no,emp_name,sum(tot_amt)
fromemployeea,salesb
wherea.emp_no=b.sale_id
groupbyemp_no,emp_name
havingsum(tot_amt)=
(selectmax(totamt)
from(selectsale_id,sum(tot_amt)totamt
fromsales
groupbysale_id)c) 53、查詢每位客戶所訂購的每種產(chǎn)品的詳細(xì)清單,要求顯示出客戶號(hào),客戶名,產(chǎn)品號(hào),產(chǎn)品名,數(shù)量及單價(jià)。
selecta.cust_id,cust_name,c.prod_id,prod_name,qty,unit_price
fromcustomera,salesb,sale_itemc,productd
wherea.cust_id=b.cust_idandb.order_no=c.order_noandc.prod_id=d.prod_id 54、求各部門的平均薪水,要求按平均薪水從小到大排序。
selectdept,avg(salary)
fromemployee
groupbydept
orderbyavg(salary)

美國快速服務(wù)器

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對(duì)1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部