偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

DB2數(shù)據(jù)庫(kù)必須掌握的常用語(yǔ)句(二)

數(shù)據(jù)庫(kù)
如果您是剛剛開(kāi)始學(xué)習(xí)數(shù)據(jù)庫(kù),那么本文要將的DB2數(shù)據(jù)庫(kù)的常用命令,對(duì)您的學(xué)習(xí)是很有用處的,掌握了這些常用命令,那么在以后的學(xué)習(xí)中遇到這些命令時(shí)就不會(huì)長(zhǎng)丈二的和尚摸不著頭腦啦。

DB2數(shù)據(jù)庫(kù)的常用命令之前已經(jīng)為大家介紹過(guò)了,即DB2數(shù)據(jù)庫(kù)必須掌握的常用語(yǔ)句(一),接下來(lái)就為大家介紹更多的DB2數(shù)據(jù)庫(kù)常用語(yǔ)句。

1、用存在量詞查找沒(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)

2、使用左外連接查找每個(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
 

 

3、查找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

4、查找每個(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

5、查找銷(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

6、查找銷(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

7、查找至少銷(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 )

8、查找至少與世界技術(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)

)

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

select emp_no,emp_name,dept,salary

from employee

where emp_name like '劉%'

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

select cust_id

from sales

where tot_amt>2000

很高興與大家分享DB2數(shù)據(jù)庫(kù)常用語(yǔ)句,希望能對(duì)大家有所幫助。
 

【編輯推薦】

  1. DB2數(shù)據(jù)庫(kù)卸載的常用問(wèn)題分析及方法
  2. DB2數(shù)據(jù)庫(kù)授權(quán)詳解
  3. 解析DB2數(shù)據(jù)庫(kù)恢復(fù)概念
責(zé)任編輯:迎迎 來(lái)源: 天極網(wǎng)
相關(guān)推薦

2011-03-16 10:10:39

DB2數(shù)據(jù)庫(kù)常用命令

2011-03-16 10:59:34

DB2數(shù)據(jù)庫(kù)常用語(yǔ)句

2011-03-16 10:39:11

DB2數(shù)據(jù)庫(kù)常用語(yǔ)句

2011-03-16 10:12:14

DB2數(shù)據(jù)庫(kù)常用語(yǔ)句

2010-11-04 12:00:59

db2存儲(chǔ)過(guò)程

2010-08-09 13:08:45

DB2數(shù)據(jù)庫(kù)

2010-08-10 09:07:51

DB2數(shù)據(jù)庫(kù)優(yōu)化

2010-07-29 09:44:35

DB2數(shù)據(jù)庫(kù)優(yōu)化

2010-09-06 10:00:00

DB2數(shù)據(jù)庫(kù)

2010-08-25 15:13:22

DB2Oracle數(shù)據(jù)庫(kù)

2010-04-13 15:24:25

Oracle維護(hù)常用語(yǔ)

2011-03-11 16:02:03

DB2數(shù)據(jù)庫(kù)安裝

2010-07-27 08:48:52

DB2數(shù)據(jù)庫(kù)優(yōu)化

2011-08-31 16:33:00

DB2

2010-10-08 10:18:26

MySQL自增字段

2010-11-03 16:32:10

DB2創(chuàng)建數(shù)據(jù)庫(kù)

2011-03-16 13:21:04

IBM DB2數(shù)據(jù)庫(kù)性能參數(shù)

2010-08-25 10:50:48

DB2數(shù)據(jù)庫(kù)

2010-06-01 16:02:00

MySQL 常用語(yǔ)句

2010-08-31 17:34:46

DB2
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)