Sei sulla pagina 1di 6

1. Show the ages and salaries of all salespeople. SELECT AGE, SALARY FROM TBLSALESPERSON; 2.

Show the ages and salaries of all salespeople but omit duplicates. SELECT DISTINCT AGE, SALARY FROM TBLSALESPERSON; 3. Show the names of salespeople under 30 years old. SELECT NAME FROM TBLSALESPERSON WHERE AGE < 30; 4. Show the names of all salespeople who have an order with Abernathy Constructi on. SELECT TBLSALESPERSON.NAME FROM (TBLSALESPERSON INNER JOIN TBLORDER ON TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME) WHERE TBLORDER.CUSTNAME = 'ABERNATHY CONSTRUCTION'; 5. Show the names of all salespeople who earn more than $49,999 and less than $1 00,000. SELECT NAME FROM TBLSALESPERSON WHERE SALARY < 100000 AND SALARY > 49999; 6. Show the names of all salespeople in their fifties. Use the between keyword. SELECT NAME FROM TBLSALESPERSON WHERE AGE BETWEEN 50 AND 59; 7. Show the names of all salespeople in their fifties. Use the like keyword. SELECT NAME FROM TBLSALESPERSON WHERE CSTR(AGE) LIKE '5?'; 8. Show the names of customers which are located in a city ending with S. SELECT NAME FROM TBLCUSTOMER WHERE RIGHT$(CITY,1) = 'S'; 9. Show the names and salary of all salespeople who do not have an order with Ab ernathy Construction, in ascending order of salary.

SELECT TBLSALESPERSON.NAME, SALARY FROM TBLSALESPERSON WHERE NOT EXISTS (SELECT * FROM TBLORDER WHERE TBLORDER.CUSTNAME = 'ABERNATHY CONSTRUCTION' AND TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME) ORDER BY SALARY; 10. Compute the number of orders. SELECT Count(NUMBER) AS COUNT_OF_ORDERS FROM TBLORDER; 11. Compute the number of different customers who have an order. SELECT COUNT(CUSTNAME) AS NUM_CUST_WITH_ORDERS FROM (SELECT DISTINCT CUSTNAME FROM TBLORDER); 12. Compute the average age of a salesperson. SELECT AVG(AGE) AS AVERAGE_AGE FROM TBLSALESPERSON; 13. Show the name of the oldest salesperson. SELECT NAME FROM TBLSALESPERSON, (SELECT MAX(AGE) AS OLDEST FROM TBLSALESPERSON) WHERE AGE=OLDEST; SELECT NAME FROM TBLSALESPERSON, (SELECT MAX(AGE) AS OLDEST FROM TBLSALESPERSON AS OLD_PEOPLE) WHERE AGE=OLDEST; SELECT NAME FROM TBLSALESPERSON, (SELECT MAX(AGE) AS OLDEST FROM TBLSALESPERSON) AS OLD_PEOPLE WHERE AGE=OLD_PEOPLE.OLDEST; SELECT NAME FROM TBLSALESPERSON, (SELECT MAX(AGE) AS OLDEST FROM TBLSALESPERSON) AS OLD_PEOPLE WHERE TBLSALESPERSON.AGE=OLD_PEOPLE.OLDEST;

14. Compute the number of orders for each salesperson. SELECT SALESPERSONNAME, COUNT(SALESPERSONNAME) AS NUMBER_OF_ORDERS FROM TBLORDER GROUP BY SALESPERSONNAME; SELECT TBLSALESPERSON.NAME, COUNT(TBLORDER.SALESPERSONNAME) AS COUNT_OF_ORDERS FROM TBLSALESPERSON LEFT JOIN TBLORDER ON TBLSALESPERSON.NAME = TBLORDER.SALESPE RSONNAME GROUP BY TBLSALESPERSON.NAME; 15. Compute the number of orders for each salesperson, considering only orders f or an amount exceeding 500. SELECT SALESPERSONNAME, COUNT(SALESPERSONNAME) AS NUMBER_OF_ORDERS_OVER_500 FROM TBLORDER HAVING AMOUNT > 500 GROUP BY SALESPERSONNAME; 16. Show the names and ages of salespeople who have an order with Abernathy Cons truction, in descending order of age (use a subquery). SELECT TBLSALESPERSON.NAME, AGE FROM TBLSALESPERSON WHERE EXISTS (SELECT * FROM TBLORDER WHERE TBLORDER.CUSTNAME = 'ABERNATHY CONSTRUCTION' AND TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME) ORDER BY AGE DESC; 17. Show the names and ages of salespeople who have an order with Abernathy Cons truction, in descending order of age (use a join). SELECT TBLSALESPERSON.NAME, AGE FROM TBLSALESPERSON INNER JOIN TBLORDER ON TBLSALESPERSON.NAME = TBLORDER.SALESP ERSONNAME WHERE TBLORDER.CUSTNAME = 'ABERNATHY CONSTRUCTION' ORDER BY AGE DESC; 18. Show the ages of all salespeople who have an order with a customer in Memphi s (use a subquery). SELECT AGE FROM TBLSALESPERSON WHERE EXISTS (SELECT * FROM TBLORDER WHERE TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME AND EXISTS (SELECT * FROM TBLCUSTOMER

WHERE TBLORDER.CUSTNAME = TBLCUSTOMER.NAME AND TBLCUSTOMER.CITY = 'MEMPHIS' )); 19. Show the ages of all salespeople who have an order with a customer in Memphi s (use a join). SELECT AGE FROM TBLSALESPERSON INNER JOIN (TBLORDER INNER JOIN TBLCUSTOMER ON TBLORDER.CUST NAME = TBLCUSTOMER.NAME) ON TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME WHERE TBLCUSTOMER.CITY = 'MEMPHIS'; 20. Show the industry type and ages of the salespeople of all orders for compani es in Memphis. SELECT INDUSTRYTYPE,AGE FROM TBLCUSTOMER INNER JOIN (TBLORDER INNER JOIN TBLSALESPERSON ON TBLORDER.SALESPERSONNAME = TBLSALESPERSON.NAME) ON TBLCUSTOMER.NAME = TBLORDER.CUSTNAME WHERE TBLCUSTOMER.CITY = 'MEMPHIS'; 21. Show the names of salespeople along with the names of the customers which ha ve ordered from them. Include salespeople who have had no orders. (use a left or right join). SELECT TBLSALESPERSON.NAME, TBLORDER.CUSTNAME FROM TBLSALESPERSON LEFT JOIN TBLORDER ON TBLSALESPERSON.NAME = TBLORDER.SALESPE RSONNAME; 22. Show the names of salespeople who have two or more orders. SELECT SALESPERSONNAME FROM TBLORDER GROUP BY SALESPERSONNAME HAVING COUNT(SALESPERSONNAME) > 1; 23. Show the names and ages of salespeople who have two or more orders. SELECT TBLSALESPERSON.NAME, AGE FROM TBLSALESPERSON INNER JOIN TBLORDER ON TBLSALESPERSON.NAME = TBLORDER.SALESP ERSONNAME GROUP BY TBLSALESPERSON.NAME, AGE HAVING COUNT(TBLORDER.SALESPERSONNAME) > 1; 24. Show the names and ages of salespeople who have an order with all customers. SELECT DISTINCT TBLSALESPERSON.NAME, TBLSALESPERSON.AGE FROM TBLSALESPERSON INNER JOIN (TBLCUSTOMER INNER JOIN TBLORDER ON TBLCUSTOMER.N AME = TBLORDER.CUSTNAME) ON TBLSALESPERSON.NAME = TBLORDER.SALESPERSONNAME GROUP BY TBLSALESPERSON.NAME, TBLSALESPERSON.AGE HAVING COUNT(TBLSALESPERSON.NAME)=(SELECT COUNT (TBLCUSTOMER.NAME) FROM TBLCUSTOMER);

25. Insert a new row into tblcustomer. Use Make Table query RestoreCustomer to restore from backup copy of tblCustomer called tblCustomerBackup INSERT INTO TBLCUSTOMER (NAME, INDUSTRYTYPE, CITY) VALUES ( "X", "A", "YPSILANTi"); 26. Insert a new name and age into tblsalesperson assume that salary is not determined. Use Make Table query RestoreSalesPerson to restore from backup copy of tblSalesPersonBackup called tblSalesPersonBackup INSERT INTO TBLSALESPERSON (NAME, AGE) VALUES ( "Lucy", "7"); 27. Insert rows into a new table, tblhighachiever. Include the fields name a nd age. To be in the new table, a salesperson must have a salary of at least 100 ,000. SELECT NAME, AGE INTO TBLHIGHACHIEVERS FROM TBLSALESPERSON WHERE SALARY > 100000; 28. Delete customer Abernathy Construction. Use Make Table query RestoreCust omer to restore from backup copy of tblCustomer called tblCustomerBackup DELETE * FROM TBLCUSTOMER WHERE NAME = 'ABERNATHY CONSTRUCTION'; 29. Delete all orders for Abernathy Construction. Use Make Table query Resto reOrder to restore from backup copy of tblOrder called tblOrderBackup DELETE * FROM TBLORDER WHERE CUSTNAME = 'ABERNATHY CONSTRUCTION'; 30. Change the salary of salesperson Jones to 45,000. Use Make Table query R estoreSalesPerson to restore from backup copy of tblSalesPersonBackup called tbl SalesPersonBackup UPDATE TBLSALESPERSON SET SALARY=45000 WHERE NAME = 'JONES'; 31. Give all salespeople a 10 percent pay increase. Use Make Table query Res toreSalesPerson to restore from backup copy of tblSalesPersonBackup called tblSa lesPersonBackup UPDATE TBLSALESPERSON SET SALARY = SALARY*1.10; 32. Change salesperson Jones's name to Parks. Use Make Table query RestoreSa lesPerson to restore from backup copy of tblSalesPersonBackup called tblSalesPer

sonBackup UPDATE TBLSALESPERSON SET NAME = 'PARKS' WHERE NAME = 'JONES'; 33. Create a table with the same name as your first name. Include the follow ing fields member#, firstname, lastname. For member#, data type is text and fie ld size is 12. For firstname datatype is text and field size is 14. For lastname data type is text, use the default size for the fields size. Don't assume the d efault size is 50, let Access fill that in for you. Create a table with the same name as your last name. This table will have 7 fields in it. Include the follow ing fields member#, ymdeff, ymdend, PCP DR, yearsexperience, caprate, level. Fo r member#, data type is text and field size is 12. For ymdeff datatype is date/t ime. For ymdend data type is data/time. For PCP DR the data type is text and fie ld size is 49. For yearsexperience the datatype is number and field size is inte ger. For caprate the data type is number and field size is double. For level the data type is number and the field size is long integer. CREATE TABLE BRIAN ([member#] CHAR(12), firstname CHAR(14), lastname CHAR); CREATE TABLE GOLDBERG ([member#] CHAR(12), ymdeff DATETIME, ymdend DATETIME, [PCP DR] CHAR(49), yearsexperience SHORT, caprate DOUBLE, level LONG);

Potrebbero piacerti anche