自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

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

1、用存在量詞查找沒有訂貨記錄的客戶名稱

select cust_name

from customer a

where not exists

(select *

from sales b

where a.cust_id=b.cust_id)

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

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的銷售情況,要求顯示相應(yīng)的銷售員的姓名、性別,銷售日期、銷售數(shù)量和金額,其中性別用男、女表示

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

when 'f' then '女'

else '未'

end,

銷售日期= 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、查找每個人的銷售記錄,要求顯示銷售員的編號、姓名、性別、產(chǎn)品名稱、數(shù)量、單價、金額和銷售日期

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

when 'f' then '女'

else '未'

end,

prod_name 產(chǎn)品名稱,銷售日期= 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、查找銷售金額***的客戶名稱和總貨款

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、查找銷售總額少于1000元的銷售員編號、姓名和銷售額

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、查找至少銷售了3種商品的客戶編號、客戶名稱、商品編號、商品名稱、數(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ù)開發(fā)公司銷售相同的客戶編號、名稱和商品編號、商品名稱、數(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ù)開發(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、查找表中所有姓劉的職工的工號,部門,薪水

select emp_no,emp_name,dept,salary

from employee

where emp_name like '劉%'

10、查找所有定單金額高于2000的所有客戶編號

select cust_id

from sales

where tot_amt>2000

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

【編輯推薦】

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

2011-03-16 10:12:14

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

2011-03-16 10:39:11

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

2011-03-16 10:10:39

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

2011-03-16 10:59:34

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

2010-11-04 12:00:59

db2存儲過程

2010-08-10 09:07:51

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

2010-08-09 13:08:45

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

2010-07-29 09:44:35

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

2010-09-06 10:00:00

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

2010-04-13 15:24:25

Oracle維護常用語

2010-08-25 15:13:22

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

2011-03-11 16:02:03

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

2010-07-27 08:48:52

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

2010-10-08 10:18:26

MySQL自增字段

2011-08-31 16:33:00

DB2

2010-11-03 16:32:10

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

2010-06-01 16:02:00

MySQL 常用語句

2011-03-04 17:54:45

DB2數(shù)據(jù)庫卸載

2010-08-25 10:50:48

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

2010-09-01 13:38:41

DB2數(shù)據(jù)復(fù)制
點贊
收藏

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