sql question# JobHunting - 待字闺中
a*u
1 楼
Question:
please, as simply as possible, design a single table to hold orders made by
customers. You may assume details (including names) about customers are
held in some other table. Using the table that you designed for orders, and
this other table, present a single query that gives the number of orders
for every customer, one line per customer.
My answer:
1. table design
Table: Orders
order_id Long int Primary key (auto increase)
customer_id Long int Foreign key
order_date date
… (other information about the order)
Table: Customers
customer_id Long int Primary key (auto increase)
customer_name string
… (other information about the customer)
2. SQL statement
SELECT Customers. customer_name, COUNT(Orders. order_id) AS Ordernum
FROM Customers
INNER JOIN Orders
ON Customers. customer_id =Orders. customer_id
ORDER BY Customers. customer_name
However, they said my answer is not correct, why?
Thank you very much!
please, as simply as possible, design a single table to hold orders made by
customers. You may assume details (including names) about customers are
held in some other table. Using the table that you designed for orders, and
this other table, present a single query that gives the number of orders
for every customer, one line per customer.
My answer:
1. table design
Table: Orders
order_id Long int Primary key (auto increase)
customer_id Long int Foreign key
order_date date
… (other information about the order)
Table: Customers
customer_id Long int Primary key (auto increase)
customer_name string
… (other information about the customer)
2. SQL statement
SELECT Customers. customer_name, COUNT(Orders. order_id) AS Ordernum
FROM Customers
INNER JOIN Orders
ON Customers. customer_id =Orders. customer_id
ORDER BY Customers. customer_name
However, they said my answer is not correct, why?
Thank you very much!