Guest User

Untitled

a guest
Jan 12th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. drop table if exists product;
  2. drop table if exists region;
  3. drop table if exists price;
  4.  
  5. create table product(id int, name varchar(99));
  6. create table region(id int, name varchar(99));
  7. create table price(productId int, regionId int, price decimal(9, 2));
  8.  
  9. insert into product values(1, 'Crab');
  10. insert into product values(2, 'Crayfish');
  11. insert into region values(1, 'Kiev');
  12. insert into region values(2, 'Kharkov');
  13. insert into region values(3, 'Lvov');
  14. insert into price values(1, 1, 100);
  15. insert into price values(1, 2, 100);
  16. insert into price values(1, 3, 200);
  17. insert into price values(2, 1, 200);
  18. insert into price values(2, 2, 100);
  19. insert into price values(2, 3, 100);
  20.  
  21. select pt.name, rg.name, pr.price
  22. from price pr
  23. left join product pt on pt.id = pr.productId
  24. left join region rg on rg.id = pr.regionId
  25. group by pt.name having min(pr.price)
Add Comment
Please, Sign In to add comment