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

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

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

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

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

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

when 'f' then '女'

else '未'

end,

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

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

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

when 'f' then '女'

else '未'

end,

prod_name 產品名稱,銷售日期= isnull(convert(char(10),c.order_date,120),'日期不詳'),

qty 數量, 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種商品的客戶編號、客戶名稱、商品編號、商品名稱、數量和金額

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、查找至少與世界技術開發公司銷售相同的客戶編號、名稱和商品編號、商品名稱、數量和金額

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='世界技術開發公司' 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數據庫常用語句,希望能對大家有所幫助。
 

【編輯推薦】

  1. DB2數據庫卸載的常用問題分析及方法
  2. DB2數據庫授權詳解
  3. 解析DB2數據庫恢復概念
責任編輯:迎迎 來源: 天極網
相關推薦

2011-03-16 10:10:39

DB2數據庫常用命令

2011-03-16 10:59:34

DB2數據庫常用語句

2011-03-16 10:39:11

DB2數據庫常用語句

2011-03-16 10:12:14

DB2數據庫常用語句

2010-11-04 12:00:59

db2存儲過程

2010-08-09 13:08:45

DB2數據庫

2010-07-29 09:44:35

DB2數據庫優化

2010-08-10 09:07:51

DB2數據庫優化

2010-09-06 10:00:00

DB2數據庫

2010-08-25 15:13:22

DB2Oracle數據庫

2010-04-13 15:24:25

Oracle維護常用語

2011-08-31 16:33:00

DB2

2011-03-11 16:02:03

DB2數據庫安裝

2010-07-27 08:48:52

DB2數據庫優化

2010-10-08 10:18:26

MySQL自增字段

2011-03-16 13:21:04

IBM DB2數據庫性能參數

2010-08-31 17:34:46

DB2

2010-11-01 13:45:16

DB2數據庫的優勢

2010-06-01 16:02:00

MySQL 常用語句

2010-08-05 16:13:20

DB2數據庫
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲成人自拍 | 精产国产伦理一二三区 | 91高清在线观看 | 中文字幕精品视频 | 国产四虎 | 免费看91| 久久久综合精品 | 在线视频成人 | 亚洲欧美中文日韩在线v日本 | 国产精品999 | 欧美大片一区 | 午夜小视频免费观看 | 欧美亚洲国产成人 | 夜夜爽99久久国产综合精品女不卡 | 一区二区三区四区在线视频 | 国产精品视频观看 | 亚洲国产一区二区三区四区 | 亚洲人免费视频 | 国产精品美女久久久久久久久久久 | 天天操天天摸天天爽 | 成年视频在线观看福利资源 | 亚洲欧美中文日韩在线 | 成人在线免费 | www.免费看片.com | 色综合99| 中文字幕亚洲精品 | 黄视频网站免费观看 | av在线播放网站 | 一区二区三区在线观看视频 | 黄色片网站在线观看 | 毛片网在线观看 | 国产精品一区二区精品 | 国产精品高潮呻吟久久av野狼 | 亚州精品天堂中文字幕 | 性做久久久久久免费观看欧美 | 黄网站在线观看 | 国产婷婷| 久久久久久久久久久福利观看 | 91精品在线播放 | 国产乱码精品一区二区三区忘忧草 | 久久久久国产 |