SQL 查询使用COUNT函数一个方法

2025-03-23 12:06:59
推荐回答(4个)
回答1:

select 字段a,
count(case when (条件) then 表1.字段b end) as c
from 表1 inner join 表2 on 表1.字段=表2.字段
可以用case加条件。

回答2:

简单
select * from(select 字段a,count(表1.字段b) as c from 表1 inner join 表2 on 表1.字段=表2.字段)
as x where x.c 加条件

回答3:

select 字段a,count(表1.字段b) as c from 表1 inner join 表2 on 表1.字段=表2.字段 WHERE ...

回答4:

接着你那句:加 group by 字段a having c 条件(比如>2)