热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

学习DB2数据库必须掌握的五十四条常用语句 (4)

来源: 作者: 时间:2008-05-09 Tag: 点击:

40、 查询sales表中订单金额最高的订单号及订单金额

Select order_no,tot_amt from sales

where tot_amt=(select max(tot_amt) from sales)

 

41、 查询在每张订单中订购金额超过4000元的客户名及其地址

Select cust_name,addr from customer a,sales b

where a.cust_id=b.cust_id and tot_amt>4000

 

42、 求出每位客户的总订购金额,显示出客户号及总订购金额,并按总订购金额降序排列

Select cust_id,sum(tot_amt) from sales

Group by cust_id

Order by sum(tot_amt) desc

 

 

43、 求每位客户订购的每种产品的总数量及平均单价,并按客户号,产品号从小到大排列

Select cust_id,prod_id,sum(qty),sum(qty*unit_price)/sum(qty)

From sales a, sale_item b

Where a.order_no=b.order_no

Group by cust_id,prod_id

Order by cust_id,prod_id

 

44、 查询订购了三种以上产品的订单号

Select order_no

from sale_item

Group by order_no

Having count(*)>3 

最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册