Advertisement
Guest User

BAZY CW7

a guest
Dec 9th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. 1.
  2.  
  3. postgres=> SELECT DISTINCT miasto
  4. postgres-> FROM s290537_pracownicy;
  5. miasto
  6. ----------
  7. Warszawa
  8. Lublin
  9. Krakow
  10. Katowice
  11. (4 rows)
  12.  
  13. 2.
  14.  
  15. postgres=> SELECT miasto
  16. postgres-> FROM s290537_pracownicy
  17. postgres-> GROUP BY miasto;
  18. miasto
  19. ----------
  20. Warszawa
  21. Lublin
  22. Krakow
  23. Katowice
  24. (4 rows)
  25.  
  26. 3.
  27.  
  28. postgres=> SELECT
  29. postgres-> count(DISTINCT miasto)
  30. postgres-> FROM s290537_pracownicy;
  31. count
  32. -------
  33. 4
  34. (1 row)
  35.  
  36. 4.
  37.  
  38. postgres=> select distinct miasto, zawod from s290537_pracownicy order by miasto asc;
  39. miasto | zawod
  40. ----------+-------------
  41. Katowice | scenarzysta
  42. Katowice | rezyser
  43. Krakow | scenarzysta
  44. Krakow | rezyser
  45. Lublin | rezyser
  46. Warszawa | rezyser
  47. Warszawa | scenarzysta
  48. (7 rows)
  49.  
  50. 5.
  51.  
  52. postgres=> SELECT
  53. postgres-> miasto,
  54. postgres-> COUNT (miasto)
  55. postgres-> FROM s290537_pracownicy
  56. postgres-> GROUP BY miasto;
  57. miasto | count
  58. ----------+-------
  59. Warszawa | 5
  60. Lublin | 1
  61. Krakow | 4
  62. Katowice | 3
  63. (4 rows)
  64.  
  65. 6.
  66.  
  67. postgres=> SELECT
  68. postgres-> DISTINCT miasto, zawod,
  69. postgres-> COUNT(zawod)
  70. postgres-> FROM s290537_pracownicy
  71. postgres-> GROUP BY miasto,zawod;
  72. miasto | zawod | count
  73. ----------+-------------+-------
  74. Warszawa | scenarzysta | 3
  75. Katowice | scenarzysta | 1
  76. Lublin | rezyser | 1
  77. Krakow | scenarzysta | 2
  78. Warszawa | rezyser | 2
  79. Krakow | rezyser | 2
  80. Katowice | rezyser | 2
  81. (7 rows)
  82.  
  83. 7.
  84.  
  85. postgres=> SELECT
  86. postgres-> AVG(placa)
  87. postgres-> FROM s290537_pracownicy;
  88. avg
  89. ------------------
  90. 2261.53846153846
  91. (1 row)
  92.  
  93. 8.
  94.  
  95. postgres=> SELECT
  96. postgres-> miasto,
  97. postgres-> AVG(placa)
  98. postgres-> FROM s290537_pracownicy
  99. postgres-> GROUP BY miasto;
  100. miasto | avg
  101. ----------+------------------
  102. Warszawa | 3400
  103. Lublin | 1000
  104. Krakow | 1550
  105. Katowice | 1733.33333333333
  106. (4 rows)
  107.  
  108. 9.
  109.  
  110. postgres=> SELECT
  111. postgres-> DISTINCT miasto, zawod,
  112. postgres-> AVG(placa)
  113. postgres-> FROM s290537_pracownicy
  114. postgres-> GROUP BY miasto,zawod;
  115. miasto | zawod | avg
  116. ----------+-------------+------
  117. Krakow | scenarzysta | 1500
  118. Warszawa | rezyser | 3250
  119. Warszawa | scenarzysta | 3500
  120. Katowice | scenarzysta | 2000
  121. Katowice | rezyser | 1600
  122. Krakow | rezyser | 1600
  123. Lublin | rezyser | 1000
  124. (7 rows)
  125.  
  126. 10.
  127.  
  128. postgres=> SELECT
  129. postgres-> miasto,
  130. postgres-> AVG(placa)
  131. postgres-> FROM s290537_pracownicy
  132. postgres-> GROUP BY miasto
  133. postgres-> HAVING COUNT(miasto)>2;
  134. miasto | avg
  135. ----------+------------------
  136. Warszawa | 3400
  137. Krakow | 1550
  138. Katowice | 1733.33333333333
  139. (3 rows)
  140.  
  141. 11.
  142.  
  143. postgres=> SELECT
  144. postgres-> zawod,
  145. postgres-> avg(placa)
  146. postgres-> FROM s290537_pracownicy
  147. postgres-> GROUP BY zawod;
  148. zawod | avg
  149. -------------+------------------
  150. rezyser | 1985.71428571429
  151. scenarzysta | 2583.33333333333
  152. (2 rows)
  153.  
  154. 12.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement