1

我是一名海外学生,所以我不熟悉“信用系统”,但我有一个与之相关的数据库问题。我只是不能很好地理解它。

这里是问题:

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

数据库的架构是:

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;
4

1 回答 1

0

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

于 2013-08-01T06:01:08.010 回答