Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- postgres=> SELECT DISTINCT miasto
- postgres-> FROM s290537_pracownicy;
- miasto
- ----------
- Warszawa
- Lublin
- Krakow
- Katowice
- (4 rows)
- 2.
- postgres=> SELECT miasto
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto;
- miasto
- ----------
- Warszawa
- Lublin
- Krakow
- Katowice
- (4 rows)
- 3.
- postgres=> SELECT
- postgres-> count(DISTINCT miasto)
- postgres-> FROM s290537_pracownicy;
- count
- -------
- 4
- (1 row)
- 4.
- postgres=> select distinct miasto, zawod from s290537_pracownicy order by miasto asc;
- miasto | zawod
- ----------+-------------
- Katowice | scenarzysta
- Katowice | rezyser
- Krakow | scenarzysta
- Krakow | rezyser
- Lublin | rezyser
- Warszawa | rezyser
- Warszawa | scenarzysta
- (7 rows)
- 5.
- postgres=> SELECT
- postgres-> miasto,
- postgres-> COUNT (miasto)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto;
- miasto | count
- ----------+-------
- Warszawa | 5
- Lublin | 1
- Krakow | 4
- Katowice | 3
- (4 rows)
- 6.
- postgres=> SELECT
- postgres-> DISTINCT miasto, zawod,
- postgres-> COUNT(zawod)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto,zawod;
- miasto | zawod | count
- ----------+-------------+-------
- Warszawa | scenarzysta | 3
- Katowice | scenarzysta | 1
- Lublin | rezyser | 1
- Krakow | scenarzysta | 2
- Warszawa | rezyser | 2
- Krakow | rezyser | 2
- Katowice | rezyser | 2
- (7 rows)
- 7.
- postgres=> SELECT
- postgres-> AVG(placa)
- postgres-> FROM s290537_pracownicy;
- avg
- ------------------
- 2261.53846153846
- (1 row)
- 8.
- postgres=> SELECT
- postgres-> miasto,
- postgres-> AVG(placa)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto;
- miasto | avg
- ----------+------------------
- Warszawa | 3400
- Lublin | 1000
- Krakow | 1550
- Katowice | 1733.33333333333
- (4 rows)
- 9.
- postgres=> SELECT
- postgres-> DISTINCT miasto, zawod,
- postgres-> AVG(placa)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto,zawod;
- miasto | zawod | avg
- ----------+-------------+------
- Krakow | scenarzysta | 1500
- Warszawa | rezyser | 3250
- Warszawa | scenarzysta | 3500
- Katowice | scenarzysta | 2000
- Katowice | rezyser | 1600
- Krakow | rezyser | 1600
- Lublin | rezyser | 1000
- (7 rows)
- 10.
- postgres=> SELECT
- postgres-> miasto,
- postgres-> AVG(placa)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY miasto
- postgres-> HAVING COUNT(miasto)>2;
- miasto | avg
- ----------+------------------
- Warszawa | 3400
- Krakow | 1550
- Katowice | 1733.33333333333
- (3 rows)
- 11.
- postgres=> SELECT
- postgres-> zawod,
- postgres-> avg(placa)
- postgres-> FROM s290537_pracownicy
- postgres-> GROUP BY zawod;
- zawod | avg
- -------------+------------------
- rezyser | 1985.71428571429
- scenarzysta | 2583.33333333333
- (2 rows)
- 12.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement