简体   繁体   中英

Customers credit system, oracle SQL

I am an oversea student, so I am not familiar with "Credit System" but I have a database question which is related to it. I just could not understand it well.

Here it the question:

Write a query: The billing officer would like to know which customers are currently over their credit limit.

The schema of database is:

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)

Any idea?

Is that just :

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

or might be:

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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM