DB2數據庫的常用語句之前已經為大家介紹了很多,本文將繼續講述DB2數據庫常用語句。
1、統計表中員工的薪水在4000-6000之間的人數
select count(*)as 人數
from employee
where salary between 4000 and 6000
2、查詢表中的同一部門的職工的平均工資,但只查詢"住址"是"上海市"的員工
select avg(salary) avg_sal,dept
from employee
where addr like '上海市%'
group by dept
3、將表中住址為"上海市"的員工住址改為"北京市"
update employee
set addr like '北京市'
where addr like '上海市'
4、查找業務部或會計部的女員工的基本信息
select emp_no,emp_name,dept
from employee
where sex='F'and dept in ('業務','會計')
5、顯示每種產品的銷售金額總和,並依銷售金額由大到小輸出
select prod_id ,sum(qty*unit_price)
from sale_item
group by prod_id
order by sum(qty*unit_price) desc
6、選取編號界於'C0001'和'C0004'的客戶編號、客戶名稱、客戶地址
select CUST_ID,cust_name,addr
from customer
where cust_id between 'C0001' AND 'C0004'
7、計算出一共銷售了幾種產品
select count(distinct prod_id) as '共銷售產品數'
from sale_item
8、將業務部員工的薪水上調3%
update employee
set salary=salary*1.03
where dept='業務'
9、由employee表中查找出薪水最低的員工信息
select *
from employee
where salary=
(select min(salary )
from employee )
10、使用join查詢客戶姓名為"客戶丙"所購貨物的"客戶名稱","定單金額","定貨日期","電話號碼"
select a.cust_id,b.tot_amt,b.order_date,a.tel_no
from customer a join sales b
on a.cust_id=b.cust_id and cust_name like '客戶丙'