ModestGenius

sdtgjsdfh

Nov 27th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. create table Org0 (
  2. oid integer primary key,
  3. title varchar(20)
  4. );
  5.  
  6. create table Bill0 (
  7. bid integer primary key,
  8. bdate timestamp,
  9. oid integer references Org0 (oid)
  10. );
  11.  
  12. create table BillContent0 (
  13. beid integer primary key,
  14. bid integer references Bill0 (bid),
  15. good varchar(20),
  16. quantity float,
  17. price money
  18. );
  19.  
  20. create table Payment0 (
  21. pid integer primary key,
  22. bid integer references Bill0 (bid),
  23. pdate timestamp,
  24. psum money
  25. );
  26. insert into OrgX values (1, 'SAMSUNG');
  27. insert into OrgX values (2, 'APPLE');
  28. insert into BillX values (1, '01.01.01',1);
  29. insert into BillX values (2, '02.02.02',2);
  30. insert into BillX values (3, '03.03.03',1);
  31. insert into BillX values (4, '04.04.04',2);
  32. insert into BillX values (5, '05.05.05',1);
  33.  
  34.  
  35. insert into mOrg values (1, 'QWERTY');
  36. insert into mOrg values (2, 'ABC');
  37.  
  38. insert into BillcontentX values (1, 1 , 1, 1000, 5000);
  39. insert into BillcontentX values (2, 2 , 2 , 500, 3500);
  40. insert into BillcontentX values (3, 3 , 3, 15, 1500);
  41. insert into BillcontentX values (4, 4 , 4, 60, 3000);
  42. insert into BillcontentX values (5, 5 , 5, 10, 5000);
  43.  
  44. insert into PaymentX values (1,1,'01.01.01',5000);
  45. insert into PaymentX values (2,2,'02.02.02',3500);
  46. insert into PaymentX values (3,3,'03.03.03',1500);
  47. insert into PaymentX values (4,4,'04.04.04',0);
  48. insert into PaymentX values (5,5,'05.05.05',700);
  49.  
  50.  
  51. select good, quantity, price, quantity*price as total from billcontent9 where bid=3
  52.  
  53. select bid, title from Bill9 inner join Org9 using (oid)
  54.  
  55. select bid, title as org, quantity*price as total from Bill9 inner join Org9 using (oid) inner join billcontent9 using(bid)
  56. select good, quantity, price, quantity*price as total from billcontent9 where bid=3
  57.  
  58. select bid, title from Bill9 inner join Org9 using (oid)
  59.  
  60. select bid, title as org, quantity*price as total from Bill9 inner join Org9 using (oid) inner join billcontent9 using(bid)
  61.  
  62.  
  63. insert into GoodsX values(2,'marker', 7, 'kancelyaria', 'box')
  64.  
  65. insert into GoodsX values(3,'table', 100, 'mebel', 'scotch')
  66.  
  67. insert into GoodsX values(4,'chair', 50, 'mebel', 'scotch')
  68.  
  69. insert into GoodsX values(5,'TV', 500, 'entertainment', 'bigbox')
  70.  
  71.  
  72.  
  73. SELECT avg(CAST(price AS Numeric(10,2))) FROM GoodsX;
  74.  
  75. select type, count(good) from GoodsX group by type;
  76.  
  77.  
  78. UPDATE BillX
  79. SET sid = 1
  80. WHERE bid = 1;
  81.  
  82. UPDATE BillX
  83. SET sid = 2
  84. WHERE bid = 2;
  85.  
  86. UPDATE BillX
  87. SET sid = 3
  88. WHERE bid = 3;
  89.  
  90.  
  91. UPDATE BillX
  92. SET sid = 1
  93. WHERE bid = 4;
  94.  
  95. UPDATE BillX
  96. SET sid = 3
  97. WHERE bid = 5;
  98.  
  99. select GoodsX.type, SailorX.name, sum(BillContentX.price) as SUM from SailorX inner join BillX using (sid) inner join BillContentX using(bid) inner join GoodsX using(gid) group by GoodsX.type, SailorX.name
  100. http://nto.immpu.sgu.ru/z3.pdf
Advertisement
Add Comment
Please, Sign In to add comment