Advertisement
rootUser

(DbLab4ClassWork)

Dec 21st, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.42 KB | None | 0 0
  1. CREATE DATABASE lab6_1;
  2. USE lab6_1;
  3. CREATE TABLE orderTable
  4. (
  5. o_id VARCHAR(10),
  6. orderdate VARCHAR(100),
  7. orderprice INT,
  8. customer VARCHAR(20)
  9. );
  10. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  11. VALUES (1,'2008/11/12',1000,'hansen');
  12. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  13. VALUES (2,'2008/10/12',1600,'nilsen');
  14. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  15. VALUES (3,'2008/09/12',700,'hansen');
  16. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  17. VALUES (4,'2008/08/12',300,'hansen');
  18. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  19. VALUES (5,'2008/07/12',2000,'jensen');
  20. INSERT INTO orderTable(o_id,orderdate,orderprice,customer)
  21. VALUES (6,'2008/11/12',100,'hansen');
  22.  
  23. SELECT AVG(orderprice) AS orderAverage FROM orderTable;
  24.  
  25. SELECT customer FROM orderTable
  26. WHERE orderprice>(SELECT AVG(orderprice) AS orderAverage FROM orderTable);
  27.  
  28. SELECT COUNT(customer) FROM orderTable WHERE customer='nilsen';
  29.  
  30. SELECT COUNT(*) FROM orderTable;
  31.  
  32. /*select first(orderprice) from orderTable;*/
  33.  
  34. /*select orderprice from orderTable order by o_id limit 1;*/
  35.  
  36. SELECT top 1 orderprice FROM orderTable ORDER BY o_id;
  37.  
  38. /*select last(orderprice) from orderTable;*/
  39.  
  40. SELECT SUM(orderprice) FROM orderTable;
  41.  
  42. SELECT customer,SUM(orderprice) FROM orderTable GROUP BY customer;
  43.  
  44. SELECT customer,SUM(orderprice) FROM orderTable GROUP BY customer HAVING SUM(orderprice)<2000;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement