PostgreSQL

Скачать в pdf «PostgreSQL»


test=> SELECT COUNT(*) FROM aggtest; count


2


(1 tow)


test=> SELECT COUNT(col) FROM aggtest; count


1


(1 tow)


test=> SELECT state, COUNT(*) test-> FROM friend test-> GROUP BY state; state | count


——-+——-


MA    |    2


MD    |    1


NJ    |    2


PA    |    1


(4 rows)


test=> SELECT state, MIN(age), MAX(age), AVG(age) test-> FROM friend test-> GROUP BY state test-> ORDER BY 4 DESC;



state


| min | _+—————+_


max |


. — — — — +


avg


MA


| 24 |


33 |


28


MD


| 27 |


27 |


27


NJ


| 19 |


25 |


22


PA


| 22 |


22 |


22

(4 rows)


test=> SELECT city, state, COUNT(*) test-> FROM friend test-> GROUP BY state, city test-> ORDER BY 1, 2;


city    | state | count



test=> SELECT state, COUNT(*) test-> FROM friend test-> GROUP BY state test-> HAVING COUNT(*) > 1 test-> ORDER BY state; state | count

Скачать в pdf «PostgreSQL»