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
