色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

學(xué)習(xí)DB2數(shù)據(jù)庫(kù)必須掌握的五十四條常用語(yǔ)句

瀏覽:156日期:2023-11-08 16:16:13
DB2數(shù)據(jù)庫(kù)常用的五十四條語(yǔ)句:

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)和職稱(chēng)

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、查找商品名稱(chēng)為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ù)編號(hào)統(tǒng)計(jì)每個(gè)客戶(hù)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ù)編號(hào)、名稱(chēng)和訂單總額

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ù)編號(hào)、名稱(chēng)和訂單總額

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)有訂貨記錄的客戶(hù)名稱(chēng)

select cust_name

from customer a

where not exists

(select *

from sales b

where a.cust_id=b.cust_id)

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

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)品名稱(chēng)、數(shù)量、單價(jià)、金額和銷(xiāo)售日期

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

when 'f' then '女'

else '未'

end,

prod_name 產(chǎn)品名稱(chēng),銷(xiāo)售日期= isnull(convert(char(10),c.order_date,120),'日期不詳'),

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

from employee a left outer join sales b on a.emp_no=b.sale_id , sale_item c,product d

where d.prod_id=c.prod_id and b.order_no=c.order_no

15、查找銷(xiāo)售金額最大的客戶(hù)名稱(chēng)和總貨款

select cust_name,d.cust_sum

from customer a,

(select cust_id,cust_sum

from (select cust_id, sum(tot_amt) as cust_sum

from sales

group by cust_id ) b

where b.cust_sum =

( select max(cust_sum)

from (select cust_id, sum(tot_amt) as cust_sum

from sales

group by cust_id ) c )

) d

where a.cust_id=d.cust_id

16、查找銷(xiāo)售總額少于1000元的銷(xiāo)售員編號(hào)、姓名和銷(xiāo)售額

select emp_no,emp_name,d.sale_sum

from employee a,

(select sale_id,sale_sum

from (select sale_id, sum(tot_amt) as sale_sum

from sales

group by sale_id ) b

where b.sale_sum <1000

) d

where a.emp_no=d.sale_id

17、查找至少銷(xiāo)售了3種商品的客戶(hù)編號(hào)、客戶(hù)名稱(chēng)、商品編號(hào)、商品名稱(chēng)、數(shù)量和金額

select a.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price

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

where a.cust_id=c.cust_id and d.prod_id=b.prod_id and

c.order_no=d.order_no and a.cust_id in (

select cust_id

from (select cust_id,count(distinct prod_id) prodid

from (select cust_id,prod_id

from sales e,sale_item f

where e.order_no=f.order_no) g

group by cust_id

having count(distinct prod_id)>=3) h )

18、查找至少與世界技術(shù)開(kāi)發(fā)公司銷(xiāo)售相同的客戶(hù)編號(hào)、名稱(chēng)和商品編號(hào)、商品名稱(chēng)、數(shù)量和金額

select a.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price

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

where a.cust_id=c.cust_id and d.prod_id=b.prod_id and

c.order_no=d.order_no and not exists

(select f.*

from customer x ,sales e, sale_item f

where cust_name='世界技術(shù)開(kāi)發(fā)公司' and x.cust_id=e.cust_id and

e.order_no=f.order_no and not exists

( select g.*

from sale_item g, sales h

where g.prod_id = f.prod_id and g.order_no=h.order_no and

h.cust_id=a.cust_id)

)

19、查找表中所有姓劉的職工的工號(hào),部門(mén),薪水

select emp_no,emp_name,dept,salary

from employee

where emp_name like '劉%'

20、查找所有定單金額高于2000的所有客戶(hù)編號(hào)

select cust_id

from sales

where tot_amt>2000

21、統(tǒng)計(jì)表中員工的薪水在4000-6000之間的人數(shù)

select count(*)as 人數(shù)

from employee

where salary between 4000 and 6000

22、查詢(xún)表中的同一部門(mén)的職工的平均工資,但只查詢(xún)'住址'是'上海市'的員工

select avg(salary) avg_sal,dept

from employee

where addr like '上海市%'

group by dept

23、將表中住址為'上海市'的員工住址改為'北京市'

update employee

set addr like '北京市'

where addr like '上海市'

24、查找業(yè)務(wù)部或會(huì)計(jì)部的女員工的基本信息

select emp_no,emp_name,dept

from employee

where sex='F'and dept in ('業(yè)務(wù)','會(huì)計(jì)')

25、顯示每種產(chǎn)品的銷(xiāo)售金額總和,并依銷(xiāo)售金額由大到小輸出

select prod_id ,sum(qty*unit_price)

from sale_item

group by prod_id

order by sum(qty*unit_price) desc

26、選取編號(hào)界于'C0001'和'C0004'的客戶(hù)編號(hào)、客戶(hù)名稱(chēng)、客戶(hù)地址

select CUST_ID,cust_name,addr

from customer

where cust_id between 'C0001' AND 'C0004'

27、計(jì)算出一共銷(xiāo)售了幾種產(chǎn)品

select count(distinct prod_id) as '共銷(xiāo)售產(chǎn)品數(shù)'

from sale_item

28、將業(yè)務(wù)部員工的薪水上調(diào)3%

update employee

set salary=salary*1.03

where dept='業(yè)務(wù)'

29、由employee表中查找出薪水最低的員工信息

select *

from employee

where salary=

(select min(salary )

from employee )

30、使用join查詢(xún)客戶(hù)姓名為'客戶(hù)丙'所購(gòu)貨物的'客戶(hù)名稱(chēng)','定單金額','定貨日期','電話號(hào)碼'

select a.cust_id,b.tot_amt,b.order_date,a.tel_no

from customer a join sales b

on a.cust_id=b.cust_id and cust_name like '客戶(hù)丙'

31、由sales表中查找出訂單金額大于'E0013業(yè)務(wù)員在1996/10/15這天所接每一張訂單的金額'的所有訂單

select *

from sales

where tot_amt>all

(select tot_amt

from sales

where sale_id='E0013'and order_date='1996/10/15')

order by tot_amt

32、計(jì)算'P0001'產(chǎn)品的平均銷(xiāo)售單價(jià)

select avg(unit_price)

from sale_item

where prod_id='P0001'

33、找出公司女員工所接的定單

select sale_id,tot_amt

from sales

where sale_id in

(select sale_id from employee

where sex='F')

34、找出同一天進(jìn)入公司服務(wù)的員工

select a.emp_no,a.emp_name,a.date_hired

from employee a

join employee b

on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)

order by a.date_hired

35、找出目前業(yè)績(jī)超過(guò)232000元的員工編號(hào)和姓名

select emp_no,emp_name

from employee

where emp_no in

(select sale_id

from sales

group by sale_id

having sum(tot_amt)<232000)

36、查詢(xún)出employee表中所有女職工的平均工資和住址在'上海市'的所有女職工的平均工資

select avg(salary)

from employee

where sex like 'f'

union

select avg(salary)

from employee

where sex like 'f' and addr like '上海市%'

37、在employee表中查詢(xún)薪水超過(guò)員工平均薪水的員工信息

Select *

from employee

where salary>( select avg(salary)

from employee)

38、 找出目前銷(xiāo)售業(yè)績(jī)超過(guò)10000元的業(yè)務(wù)員編號(hào)及銷(xiāo)售業(yè)績(jī),并按銷(xiāo)售業(yè)績(jī)從大到小排序

Select sale_id ,sum(tot_amt)

from sales

group by sale_id

having sum(tot_amt)>10000

order by sum(tot_amt) desc

39、 找出公司男業(yè)務(wù)員所接且訂單金額超過(guò)2000元的訂單號(hào)及訂單金額

Select order_no,tot_amt

From sales ,employee

Where sale_id=emp_no and sex='M' and tot_amt>2000

40、 查詢(xún)sales表中訂單金額最高的訂單號(hào)及訂單金額

Select order_no,tot_amt from sales

where tot_amt=(select max(tot_amt) from sales)

41、 查詢(xún)?cè)诿繌堄唵沃杏嗁?gòu)金額超過(guò)4000元的客戶(hù)名及其地址

Select cust_name,addr from customer a,sales b

where a.cust_id=b.cust_id and tot_amt>4000

42、 求出每位客戶(hù)的總訂購(gòu)金額,顯示出客戶(hù)號(hào)及總訂購(gòu)金額,并按總訂購(gòu)金額降序排列

Select cust_id,sum(tot_amt) from sales

Group by cust_id

Order by sum(tot_amt) desc

43、 求每位客戶(hù)訂購(gòu)的每種產(chǎn)品的總數(shù)量及平均單價(jià),并按客戶(hù)號(hào),產(chǎn)品號(hào)從小到大排列

Select cust_id,prod_id,sum(qty),sum(qty*unit_price)/sum(qty)

From sales a, sale_item b

Where a.order_no=b.order_no

Group by cust_id,prod_id

Order by cust_id,prod_id

44、 查詢(xún)訂購(gòu)了三種以上產(chǎn)品的訂單號(hào)

Select order_no

from sale_item

Group by order_no

Having count(*)>3

45、 查詢(xún)訂購(gòu)的產(chǎn)品至少包含了訂單3號(hào)中所訂購(gòu)產(chǎn)品的訂單

Select distinct order_no

From sale_item a

Where order_no<>'3'and not exists (

Select * from sale_item b where order_no ='3' and not exists

(select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id))

46、 在sales表中查找出訂單金額大于'E0013業(yè)務(wù)員在1996/11/10這天所接每一張訂單的金額'的所有訂單,并顯示承接這些訂單的業(yè)務(wù)員和該訂單的金額

Select sale_id,tot_amt from sales

where tot_amt>all(select tot_amt

from sales

where sale_id='E0013' and order_date='1996-11-10')

47、 查詢(xún)末承接業(yè)務(wù)的員工的信息

Select *

From employee a

Where not exists

(select * from sales b where a.emp_no=b.sale_id)

48、 查詢(xún)來(lái)自上海市的客戶(hù)的姓名,電話、訂單號(hào)及訂單金額

Select cust_name,tel_no,order_no,tot_amt

From customer a ,sales b

Where a.cust_id=b.cust_id and addr='上海市'

49、 查詢(xún)每位業(yè)務(wù)員各個(gè)月的業(yè)績(jī),并按業(yè)務(wù)員編號(hào)、月份降序排序

Select sale_id,month(order_date), sum(tot_amt)

from sales

group by sale_id,month(order_date)

order by sale_id,month(order_date) desc

50、 求每種產(chǎn)品的總銷(xiāo)售數(shù)量及總銷(xiāo)售金額,要求顯示出產(chǎn)品編號(hào)、產(chǎn)品名稱(chēng),總數(shù)量及總金額,并按產(chǎn)品號(hào)從小到大排列

Select a.prod_id,prod_name,sum(qty),sum(qty*unit_price)

From sale_item a,product b

Where a.prod_id=b.prod_id

Group by a.prod_id,prod_name

Order by a.prod_id

51、 查詢(xún)總訂購(gòu)金額超過(guò)'C0002'客戶(hù)的總訂購(gòu)金額的客戶(hù)號(hào),客戶(hù)名及其住址

Select cust_id, cust_name,addr

From customer

Where cust_id in (select cust_id from sales

Group by cust_id

Having sum(tot_amt)>

(Select sum(tot_amt) from sales where cust_id='C0002'))

52、 查詢(xún)業(yè)績(jī)最好的的業(yè)務(wù)員號(hào)、業(yè)務(wù)員名及其總銷(xiāo)售金額

select emp_no,emp_name,sum(tot_amt)

from employee a,sales b

where a.emp_no=b.sale_id

group by emp_no,emp_name

having sum(tot_amt)=

(select max(totamt)

from (select sale_id,sum(tot_amt) totamt

from sales

group by sale_id) c)

53、 查詢(xún)每位客戶(hù)所訂購(gòu)的每種產(chǎn)品的詳細(xì)清單,要求顯示出客戶(hù)號(hào),客戶(hù)名,產(chǎn)品號(hào),產(chǎn)品名,數(shù)量及單價(jià)

select a.cust_id, cust_name,c.prod_id,prod_name,qty, unit_price

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

where a.cust_id=b.cust_id and b.order_no=c.order_no and c.prod_id=d.prod_id

54、 求各部門(mén)的平均薪水,要求按平均薪水從小到大排序

select dept,avg(salary)

from employee

group by dept

order by avg(salary)

標(biāo)簽: DB2 數(shù)據(jù)庫(kù)
主站蜘蛛池模板: 国产在线播放一区二区 | 国产精品毛片在线更新 | 免费手机黄色网址 | 久久精品国产免费观看99 | 国产成人微拍精品 | 一区二区三区视频在线 | 亚洲一级高清在线中文字幕 | 大量愉拍情侣在线视频 | 99色播 | 亚洲乱人伦精品图片 | 国产高清一区二区三区视频 | 亚洲成在人线免费视频 | 成人毛片视频免费网站观看 | 国产精品日韩欧美一区二区 | 久久天天躁综合夜夜黑人鲁色 | 国产a一级毛片午夜剧院 | 国产精品毛片天天看片 | 悟空影视大全免费高清 | 国产性大片黄在线观看在线放 | 日本一级看片免费播放 | 欧美久| 国产手机精品一区二区 | 免费亚洲视频在线观看 | 成人午夜在线 | 深夜福利亚洲 | 亚洲aⅴ| 国产三级国产精品国产国在线观看 | 狠色狠狠色狠狠狠色综合久久 | 一级做a爰片久久毛片免费看 | 欧美日韩免费做爰视频 | 欧美日韩一区二区综合 | 一级毛片不卡 | 毛片直接看 | 一级毛片在线观看视频 | 欧美激情第一欧美在线 | 欧美a一片xxxx片 | 午夜影院a级片 | www.av在线.com | 成年人色网站 | 午夜影院在线免费 | 国产黄色在线网站 |