亚洲AV无码乱码在线观看不卡|最新大伊香蕉精品视频在线|亚洲不卡av一区二区|国产美女无遮挡免费

登錄論壇 | 注冊(cè)會(huì)員 設(shè)為首頁(yè) | 收藏本站
當(dāng)前位置 : 首頁(yè)>軟件學(xué)院>數(shù)據(jù)庫(kù)>SQL>正文
 
學(xué)習(xí)DB2數(shù)據(jù)庫(kù)必須掌握的五十四條常用語(yǔ)句

http://www.yibo1263.com 2008/5/12 8:19:06  來(lái)源:ccident  編輯:張佳奇
 

1、查找員工的編號(hào)、姓名、部門(mén)和出生日期,如果出生日期為空值,顯示日期不詳,并按部門(mén)排序輸出,日期格式為yyyy-mm-dd

select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'日期不詳') birthday

from employee

order by dept

2、查找與喻自強(qiáng)在同一個(gè)單位的員工姓名、性別、部門(mén)和職稱

select emp_no,emp_name,dept,title

from employee

where emp_name<>'喻自強(qiáng)' and dept in

(select dept from employee

where emp_name='喻自強(qiáng)')

3、按部門(mén)進(jìn)行匯總,統(tǒng)計(jì)每個(gè)部門(mén)的總工資

select dept,sum(salary)

from employee

group by dept

4、查找商品名稱為14寸顯示器商品的銷(xiāo)售情況,顯示該商品的編號(hào)、銷(xiāo)售數(shù)量、單價(jià)和金額

select a.prod_id,qty,unit_price,unit_price*qty totprice

from sale_item a,product b

where a.prod_id=b.prod_id and prod_name='14寸顯示器'

5、在銷(xiāo)售明細(xì)表中按產(chǎn)品編號(hào)進(jìn)行匯總,統(tǒng)計(jì)每種產(chǎn)品的銷(xiāo)售數(shù)量和金額

select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice

from sale_item

group by prod_id

6、使用convert函數(shù)按客戶編號(hào)統(tǒng)計(jì)每個(gè)客戶1996年的訂單總金額

select cust_id,sum(tot_amt) totprice

from sales

where convert(char(4),order_date,120)='1996'

group by cust_id

7、查找有銷(xiāo)售記錄的客戶編號(hào)、名稱和訂單總額

select a.cust_id,cust_name,sum(tot_amt) totprice

from customer a,sales b

where a.cust_id=b.cust_id

group by a.cust_id,cust_name

8、查找在1997年中有銷(xiāo)售記錄的客戶編號(hào)、名稱和訂單總額

select a.cust_id,cust_name,sum(tot_amt) totprice

from customer a,sales b

where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'

group by a.cust_id,cust_name

9、查找一次銷(xiāo)售最大的銷(xiāo)售記錄

select order_no,cust_id,sale_id,tot_amt

from sales

where tot_amt=

(select max(tot_amt)

from sales)

10、查找至少有3次銷(xiāo)售的業(yè)務(wù)員名單和銷(xiāo)售日期

select emp_name,order_date

from employee a,sales b

where emp_no=sale_id and a.emp_no in

(select sale_id

from sales

group by sale_id

having count(*)>=3)

order by emp_name

11、用存在量詞查找沒(méi)有訂貨記錄的客戶名稱

select cust_name

from customer a

where not exists

(select *

from sales b

where a.cust_id=b.cust_id)

12、使用左外連接查找每個(gè)客戶的客戶編號(hào)、名稱、訂貨日期、訂單金額訂貨日期不要顯示時(shí)間,日期格式為yyyy-mm-dd按客戶編號(hào)排序,同一客戶再按訂單降序排序輸出

select a.cust_id,cust_name,convert(char(10),order_date,120),tot_amt

from customer a left outer join sales b on a.cust_id=b.cust_id

order by a.cust_id,tot_amt desc 

13、查找16M DRAM的銷(xiāo)售情況,要求顯示相應(yīng)的銷(xiāo)售員的姓名、性別,銷(xiāo)售日期、銷(xiāo)售數(shù)量和金額,其中性別用男、女表示

select emp_name 姓名, 性別= case a.sex when 'm' then '男'

when 'f' then '女'

else '未'

end,

銷(xiāo)售日期= isnull(convert(char(10),c.order_date,120),'日期不詳'),

qty 數(shù)量, qty*unit_price as 金額

from employee a, sales b, sale_item c,product d

where d.prod_name='16M DRAM' and d.prod_id=c.prod_id and

a.emp_no=b.sale_id and b.order_no=c.order_no

14、查找每個(gè)人的銷(xiāo)售記錄,要求顯示銷(xiāo)售員的編號(hào)、姓名、性別、產(chǎn)品名稱、數(shù)量、單價(jià)、金額和銷(xiāo)售日期

select emp_no 編號(hào),emp_name 姓名, 性別= case a.sex when 'm' then '男'

本新聞共4頁(yè),當(dāng)前在第1頁(yè)  1  2  3  4  

收藏】【打印】【進(jìn)入論壇
  相關(guān)文章:

·金倉(cāng)護(hù)航電力應(yīng)用數(shù)據(jù)表超越國(guó)外數(shù)據(jù)庫(kù)
·IBM收購(gòu)數(shù)據(jù)庫(kù)安全公司Guardium
·IBM或斥資2.25億美元收購(gòu)數(shù)據(jù)庫(kù)安全軟件廠商
·解決數(shù)據(jù)庫(kù)開(kāi)發(fā)中的疑難問(wèn)題
·快速了解服務(wù)器數(shù)據(jù)庫(kù)系統(tǒng)的優(yōu)點(diǎn) 
·教你為數(shù)據(jù)庫(kù)服務(wù)器配置存儲(chǔ)和內(nèi)存
·數(shù)據(jù)庫(kù)服務(wù)器安全的權(quán)限控制策略
·長(zhǎng)期使用中型Access數(shù)據(jù)庫(kù)的一點(diǎn)經(jīng)驗(yàn)
·教你簡(jiǎn)便實(shí)現(xiàn)Oracle數(shù)據(jù)庫(kù)文件移動(dòng)方法
·網(wǎng)站整體優(yōu)化之?dāng)?shù)據(jù)庫(kù)優(yōu)化
·Dreamweaver中數(shù)據(jù)庫(kù)路徑的使用

 
 
 
最新文章

搶先蘋(píng)果,消息稱英特爾芯片采用臺(tái)積電
三星揭曉業(yè)內(nèi)首款單條 512GB DDR5 內(nèi)存
vivo 高端新機(jī)爆料:120Hz 曲面屏 + 天
vivo Y21 在印度正式上市:Helio P35 芯
微星推出 GeForce RTX 3080 Sea Hawk X
消息稱三星 Galaxy Tab S8 系列平板將放
機(jī)械革命推出 F6 輕薄本:16 英寸全面屏
英特爾 12 代 Alder Lake CPU 600 系列
雷軍:向小米手機(jī) 1 首批用戶每人贈(zèng)送價(jià)
小米李明談?dòng)脩舯惶叱?nbsp;MIUI 測(cè)試版:大

推薦文章
1
2
3
4
5
6
7
8
9
10
叛逆嫩模性感寫(xiě)真
宮如敏不雅照瘋傳 看張馨予韓一菲獸獸誰(shuí)
不懼孔子搶位 阿凡達(dá)游戲影音配置推薦
2015第十七屆“東北安博會(huì)”火爆招商
第十六屆東北國(guó)際公共安全防范產(chǎn)品博覽
2016年第五屆中國(guó)國(guó)際商業(yè)信息化博覽會(huì)
2016年第五屆中國(guó)國(guó)際POS機(jī)及相關(guān)設(shè)備展
互聯(lián)網(wǎng)電視熟了嗎 2013最火電視深解析
桑達(dá)獲邀出席2015中國(guó)(廣州)國(guó)際POS機(jī)
寶獲利報(bào)名參加“2015年度中國(guó)POS機(jī)行業(yè)
八卦圖解 More>>
叛逆嫩模性感寫(xiě)真 宮如敏不雅照瘋傳 看張馨予韓一菲
周偉童魔鬼身材日本性感寫(xiě)真圖  聯(lián)想V360筆記本模特寫(xiě)真