客户信用系统,oracle SQL

时间:2013-08-01 05:50:35

标签: sql oracle credits

我是海外学生,所以我不熟悉“学分制”,但我有一个与之相关的数据库问题。我听不懂。

问题在于:

写一个查询: 计费官员想知道哪些客户目前超过了信用额度。

数据库的架构是:

Sales_Rep (SLSRep_Number [pk], Last, First, Street, City, State, Post_Code,
Total_Commission, Commission_Rate)
Customer (Customer_Number [pk], Last, First, Street, City, State, Post_Code,
Balance, Credit_Limit, SLSRep_Number [fk])
Orders (Order_Number [pk], Order_Date, Customer_Number [fk])
Part (Part_Number [pk], Part_Description, Units_on_Hand, Item_Class, Warehouse_Number, Unit_Price)
Order_Line (Order_Number, [pk1] Part_Number [pk2], Number_Ordered, Quoted_Price)

有什么想法吗?

就是这样:

Select customer_number,last,first,balance,credit_limit
from customer
where balance > credit_limit;

或者可能是:

select * from
    (select mytable.customer_number,sum(mytable.number_ordered*mytable.quoted_price) as customer_cost from
        (select customer.customer_number,order_line.number_ordered,order_line.quoted_price
        from customer,orders,order_line
        where customer.customer_number = orders.customer_number
        and orders.order_number = order_line.order_number) mytable
    group by mytable.customer_number) mytable2,customer
where customer.credit_limit < mytable2.customer_cost
and customer.customer_number = mytable2.customer_number;

1 个答案:

答案 0 :(得分:0)

第一个查询是正确的,它会给予余额超过信用额度的客户。