学习DB2数据库必须掌握的五十四条常用语句
2009-05-18 16:15:11 来源:WEB开发网47、 查询末承接业务的员工的信息
Select *
From employee a
Where not exists
(select * from sales b where a.emp_no=b.sale_id)
48、 查询来自上海市的客户的姓名,电话、订单号及订单金额
Select cust_name,tel_no,order_no,tot_amt
From customer a ,sales b
Where a.cust_id=b.cust_id and addr='上海市'
49、 查询每位业务员各个月的业绩,并按业务员编号、月份降序排序
Select sale_id,month(order_date), sum(tot_amt)
from sales
group by sale_id,month(order_date)
order by sale_id,month(order_date) desc
50、 求每种产品的总销售数量及总销售金额,要求显示出产品编号、产品名称,总数量及总金额,并按产品号从小到大排列
Select a.prod_id,prod_name,sum(qty),sum(qty*unit_price)
From sale_item a,product b
Where a.prod_id=b.prod_id
Group by a.prod_id,prod_name
Order by a.prod_id
51、 查询总订购金额超过'C0002'客户的总订购金额的客户号,客户名及其住址
Select cust_id, cust_name,addr
From customer
Where cust_id in (select cust_id from sales
Group by cust_id
Having sum(tot_amt)>
(Select sum(tot_amt) from sales where cust_id='C0002'))
52、 查询业绩最好的的业务员号、业务员名及其总销售金额
select emp_no,emp_name,sum(tot_amt)
from employee a,sales b
where a.emp_no=b.sale_id
group by emp_no,emp_name
having sum(tot_amt)=
更多精彩
赞助商链接