成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

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

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

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的銷售情況,要求顯示相應的銷售員的姓名、性別,銷售日期、銷售數(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、查找至少與世界技術開發(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='世界技術開發(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ù)庫授權詳解
  3. 解析DB2數(shù)據(jù)庫恢復概念
責任編輯:迎迎 來源: 天極網(wǎng)
相關推薦

2011-03-16 10:10:39

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

2011-03-16 10:59:34

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

2011-03-16 10:39:11

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

2011-03-16 10:12:14

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

2010-11-04 12:00:59

db2存儲過程

2010-08-09 13:08:45

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

2010-08-10 09:07:51

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

2010-07-29 09:44:35

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

2010-09-06 10:00:00

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

2010-08-25 15:13:22

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

2010-04-13 15:24:25

Oracle維護常用語

2011-03-11 16:02:03

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

2010-07-27 08:48:52

DB2數(shù)據(jù)庫優(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ù)庫

2011-03-16 13:21:04

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

2010-08-25 10:50:48

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

2010-06-01 16:02:00

MySQL 常用語句

2010-08-31 17:34:46

DB2
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产激情视频网 | 九色一区| 久久高清国产视频 | 伊人伊人 | 国产在线观看网站 | 91久久精品国产免费一区 | 91精品国产92| 91.色| 日本三级电影在线看 | 国产精品久久久久久久免费大片 | 日韩成人精品一区 | 亚洲天堂影院 | 精品1区| 日韩av免费在线观看 | 国产精品久久久久久模特 | 一区二区精品视频 | 亚洲成av | 久久久精品一区二区 | 久久高清| 精品自拍视频在线观看 | 国产精品视频一区二区三区不卡 | 91精品久久久久久久久99蜜臂 | 理论片87福利理论电影 | 亚洲精品在线视频 | 欧美精品一区免费 | 亚洲大片 | 男女搞网站 | 免费黄色在线 | 老牛影视av一区二区在线观看 | 国产成人久久精品 | 人和拘一级毛片c | 日日夜夜精品视频 | 国产在线视频一区二区董小宛性色 | 天天射天天干 | 国产视频中文字幕 | 一区二区三区四区电影 | 91欧美精品成人综合在线观看 | 国产精品一二三区 | 狠狠久| 免费在线观看黄网站 | 中文字幕在线视频一区二区三区 |