怎样用SQL语句得到查询结果的记录数

如题所述

sql中查询记录数用count函数。

1、创建测试表,插入数据:

create table test
(id int)

insert into test values (1)
insert into test values (2)
insert into test values (3)
insert into test values (null)

2、查询记录数为两种,一种是count(*),一种是count(字段值):

测试一:

select count(*) from test

结果:

测试二:

select count(id) from test

结果:

说明:如果count(字段名)的字段中含有空值,则在count中不计数,而count(*)则是查询全部的行数。

希望可以帮到您,谢谢!

温馨提示:答案为网友推荐,仅供参考