求一条SQL语句。。只返回查询到的记录条数。。不需要返回数据。。

2025-03-07 04:12:58
推荐回答(4个)
回答1:

select count (*) form user where age>20;

注意这里count (*) 是优化过的,速度绝对比count (id)快。

回答2:

select
count(case when sex ='男' then 1 else 0 end)as '男',
count(case when sex ='女' then 1 else 0 end)as '女',
count(case when age >20 then 1 else 0 end)as '大于20岁'
from TABLENAME;
返回相应记录条数

回答3:

select count(*) from table where 性别='男'

其他类似

回答4:

一楼回答不完全正确,
为什么Count(*)就是优化过的呢?
为什么所有书上都是说Count(列)比count(*)快呢?
作为一个初学者,他建的表里不一定count(*)比count(列)快
因为他不一定设了主键。