PostgreSQL COUNT 函数是最简单的函数,在计算预计由SELECT语句返回的记录数时非常有用。
要了解 COUNT 函数,请考虑将表 COMPANY 记录为跟随-
testdb# select * from COMPANY; id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Learnfk | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000 (7 rows)
现在,基于上表,假设您要计算该表中的总行数,则可以按照以下步骤进行操作:
testdb=# SELECT COUNT(*) FROM COMPANY ;
上面给出的PostgreSQL语句将产生以下输出-
count ------- 7 (1 row)
同样,您要计算Paul的记录数,则可以按以下步骤进行操作-
testdb=# SELECT COUNT(*) FROM COMPANY WHERE name='Paul';
count ------- 1 (1 row)
参考链接
https://www.learnfk.com/postgresql/postgresql-count-function.html
标签:COUNT,count,PostgreSQL,COMPANY,无涯,testdb,Paul,SELECT From: https://blog.51cto.com/u_14033984/8972523