Lisawynn
05-21-2005, 08:19 PM
Hi. I am just starting to learn SQL and have been working on a couple of questions and yes this is homework related. I am having trouble with 3 questions. I have the basis for the answers but am stuck on a couple of points. I don't expect a direct answer but a push in the right direction would be helpful. Also, if anyone can recommend additional resources for assisting with learning SQL, that would be great.
The first question is as follows:
A company is preparing invitations to its annual holiday celebration and wants to invite its sales staff (everyone in the SALESREPS table) and its customers (everyone in the CUSTOMERS table). Write a SQL statement that returns output looking like the following (including the sort order):
Bill Adams Employee
First Corp. Customer
Nancy Angelli Employee
Solomon Inc. Customer
Bill Adams is the Sales Rep for the Customer First Corp. and Nancy Angellie is the Sales Rep for the Customer Solomon Inc. This is what I have currently:
SELECT name, ‘Employee’ FROM salesreps UNION SELECT company, ‘Customers’ FROM customers ORDER BY 1, 2;
The Order By is not correct as it lists all the results for Employee and then all the results from Customers and I am trying to figure out how to get it to sort by employee, customer, employee, customer as illustrated above.
The salesrep table contains the following:
empl_num, name, age, rep_office, title, hire_date, manager, quota, sales
The customers table contains the following:
cust_num, company, cust_rep, credit_limit
The second question is:
Write a SQL statement that shows the customer number of customers that have placed an order with an amount greater than $3,000.00. List each customer number only once, and sort the results alphabetically.
This is what I have:
SELECT DISTINCT cust FROM orders WHERE amount < 3000.00;
This will return a list of customer numbers but I don't know how to sort them alphabetically because they are numerical. I know that I have to link this statement with another that incorporates the data from the customers table (the company name is alphabetical and can be sorted as such) but I am not sure how to do that. I tried using union but I don't want company to appear as a column in the results, only the numerical cust column. The customers table contains cust_num, company, cust_rep, credit_limit
The third question is:
Write a SQL statement that shows the order number, the date the order was taken and the amount of the order for all products whose product id starts with a '4' (Remember to use ANSI-compatible syntax.)
This is what I have for a solution:
SELECT order_num, order_date, amount FROM orders JOIN products ON product_id like '4%';
It produces results when the statement is executed. Would this be correct?
Thank you for your time.
The first question is as follows:
A company is preparing invitations to its annual holiday celebration and wants to invite its sales staff (everyone in the SALESREPS table) and its customers (everyone in the CUSTOMERS table). Write a SQL statement that returns output looking like the following (including the sort order):
Bill Adams Employee
First Corp. Customer
Nancy Angelli Employee
Solomon Inc. Customer
Bill Adams is the Sales Rep for the Customer First Corp. and Nancy Angellie is the Sales Rep for the Customer Solomon Inc. This is what I have currently:
SELECT name, ‘Employee’ FROM salesreps UNION SELECT company, ‘Customers’ FROM customers ORDER BY 1, 2;
The Order By is not correct as it lists all the results for Employee and then all the results from Customers and I am trying to figure out how to get it to sort by employee, customer, employee, customer as illustrated above.
The salesrep table contains the following:
empl_num, name, age, rep_office, title, hire_date, manager, quota, sales
The customers table contains the following:
cust_num, company, cust_rep, credit_limit
The second question is:
Write a SQL statement that shows the customer number of customers that have placed an order with an amount greater than $3,000.00. List each customer number only once, and sort the results alphabetically.
This is what I have:
SELECT DISTINCT cust FROM orders WHERE amount < 3000.00;
This will return a list of customer numbers but I don't know how to sort them alphabetically because they are numerical. I know that I have to link this statement with another that incorporates the data from the customers table (the company name is alphabetical and can be sorted as such) but I am not sure how to do that. I tried using union but I don't want company to appear as a column in the results, only the numerical cust column. The customers table contains cust_num, company, cust_rep, credit_limit
The third question is:
Write a SQL statement that shows the order number, the date the order was taken and the amount of the order for all products whose product id starts with a '4' (Remember to use ANSI-compatible syntax.)
This is what I have for a solution:
SELECT order_num, order_date, amount FROM orders JOIN products ON product_id like '4%';
It produces results when the statement is executed. Would this be correct?
Thank you for your time.