mysql函数count和count的区别

2025-05-13 15:05:50
推荐回答(1个)
回答1:

create table test (id int);
insert into test values(1),(2),(3),(4),(5),(6),(7),(8);
例如:查询id大于4和id=1的统计
一般写法
select count(case when id>4 then id end),count(case when id=1 then id end ) from test;
非主流写法:
select count(id>4 or null),count(id=1 or null) from test;
--------------------------------------------------------------------
以上测试通过