賽迪網 > IT技術 數據庫 > 精彩更新
  IT資訊搜索
 
IT產品搜索
[程式開發][網管世界][網路安全][數據庫技術]
[作業系統][嘉賓聊天·線上訪談][活動集錦]
[精彩專題][Symantec專區][訂閱IT技術週刊]
[開發論壇][網管論壇][安全論壇][數據庫論壇]
[作業系統論壇][Sybase專區][IBM dW技術專區]
[病毒求助][病毒與漏洞播報][文檔·源碼下載]

學習DB2數據庫必須掌握的五十四條常用語句 (1)

發佈時間:2008.05.09 04:48     來源:賽迪網    作者:Bert

【賽迪網-IT技術報道】DB2數據庫常用的五十四條語句:

1、搜尋員工的編號、姓名、部門和出生日期,如果出生日期為空值,顯示日期不詳,並按部門排序輸出,日期格式為yyyy-mm-dd

select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'日期不詳') birthday

from employee

order by dept

2、搜尋與喻自強在同一個單位的員工姓名、性別、部門和職稱

select emp_no,emp_name,dept,title

from employee

where emp_name<>'喻自強' and dept in

(select dept from employee

where emp_name='喻自強')

3、按部門進行匯總,統計每個部門的總工資

select dept,sum(salary)

from employee

group by dept

4、搜尋商品名稱為14寸顯示器商品的銷售情況,顯示該商品的編號、銷售數量、單價和金額

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、在銷售明細表中按產品編號進行匯總,統計每種產品的銷售數量和金額

select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice

from sale_item

group by prod_id

6、使用convert函數按客戶編號統計每個客戶1996年的訂單總金額

select cust_id,sum(tot_amt) totprice

from sales

where convert(char(4),order_date,120)='1996'

group by cust_id

7、搜尋有銷售記錄的客戶編號、名稱和訂單總額

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年中有銷售記錄的客戶編號、名稱和訂單總額

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、搜尋一次銷售最大的銷售記錄

select order_no,cust_id,sale_id,tot_amt

from sales

where tot_amt=

(select max(tot_amt)

from sales)

10、搜尋至少有3次銷售的業務員名單和銷售日期

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、用存在量詞搜尋沒有訂貨記錄的客戶名稱

select cust_name

from customer a

where not exists

(select *

from sales b

where a.cust_id=b.cust_id)

12、使用左外連接搜尋每個客戶的客戶編號、名稱、訂貨日期、訂單金額訂貨日期不要顯示時間,日期格式為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

1 2 3 4 下一頁>>


[ 發表評論 ] 字體[  ] [ 列印 ] [ 進入博客 ] [ 進入論壇 ]  [ 推薦給朋友 ]
  相關文章
· 帶你深入了解IBM DB2數據庫的備份與恢復 (05-08) · 解決IBM DB2數據庫鎖等待的相關問題 (05-07)
· 輕鬆解決IBM DB2數據庫鎖等待的相關問題 (05-07) · 講解DB2數據庫性能調整的十個實用技巧 (05-07)
· 教你快速掌握IBM DB2數據庫的性能參數 (05-07) · 講解IBM DB2數據庫性能調整的相關命令 (05-07)
· 講解DB2數據庫性能調整的十個實用技巧 (05-07) · 鎖現象通常分為死鎖和鎖等待兩種情形 (04-24)
· 實例講解DB2數據庫中SELECT語句高級用法 (04-22) · 在DB2數據庫中很難理解的catalog單詞 (04-17)
  客戶需求反饋表
* 姓  名:
更多資料  了解方案  認識廠商
* 單位名稱:
* 聯繫電話:
* 電子郵件:
  賽迪推薦  
  手機·資費 ·新品·導購·評測·手機資費·寬帶
手機搜索  諾基亞 N73 MOTO Z6
  IT產品 ·筆記本·臺式機·伺服器·列印·投影
IT產品搜索 
  IT技術 ·開發·網管·安全·數據庫·作業系統
  資訊化 ·熱點·專題·訪談·週刊·方案案例
· 中小企業發展緩慢 電子商務存在的問題多
· 馬雲追加20億投資淘寶 圖謀電子商務霸主
· 國產ITIL運維先行者 四大廠商角力BI市場
· 企業資訊安全解決方案 方正電子公文系統
  IT博客 ·曾劍秋·項立剛·Java學習·網管
  IT技術論壇 ·開發·網管·安全·數據庫·系統