Advertisement
taniaro

Sql Laba 2

Sep 20th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.88 KB | None | 0 0
  1. https://kripken.github.io/sql.js/GUI/
  2.  
  3. drop table if exists products;
  4. create table products (Id int not null primary key, Prodname char(25) not null,
  5.                       Manufacturer char(25) not null, Prodcount int default 0, Price int);
  6.  
  7. insert into products values (1, 'iPhone X', 'Apple', 2, 71000);
  8. insert into products values (2, 'iPhone 8', 'Apple', 3, 56000);
  9. insert into products values (3, 'Galaxy S9', 'Samsung', 1, 56000);
  10. insert into products values (4, 'Galaxy S8 plus', 'Samsung', 2, 46000);
  11. insert into products values (5, 'Desire 12', 'HTC', 3, 26000);
  12.  
  13. /*select Manufacturer from products;
  14. select distinct Manufacturer from products;
  15. select distinct Prodname, Prodcount*Price from products;
  16. select distinct Prodname, Prodcount+Price as Sum from products;
  17. select distinct Prodname, Prodcount+Price as Sum from products order by Sum;
  18.  
  19. select * from products order by Price desc limit 3;
  20. select * from products where Manufacturer!='Samsung';
  21. select * from products where Prodname like '%iPhone%';
  22.  
  23. select avg(Price) as Average_Price from products;
  24. select min(Price) as Minimum_Price from products;
  25. select max(Prodcount) as Biggest_Quantity from products;
  26.  
  27. select count(*) from products;
  28. select sum(Prodcount) from  products;
  29. select sum(Prodcount*Price) from  products;*/
  30.  
  31. insert into products values (6, 'iPhone 5C', 'Apple', 4, 12000);
  32. insert into products values (7, 'iPhone 10', 'Apple', 1, 66000);
  33. insert into products values (8, 'Galaxy S4', 'Samsung', 8, 10000);
  34. insert into products values (9, 'G345', 'LG', 0, 10000);
  35.  
  36. /*select Manufacturer, count(*) from products group by Manufacturer;
  37. select Manufacturer, sum(Prodcount) from products group by Manufacturer;
  38. select Manufacturer from products group by Manufacturer having count(Prodcount) > 1;*/
  39.  
  40. select avg(Price) as Average_Price from products;
  41. select * from products where Price > (select avg(Price) from products);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement