sql - 至少有10个

时间:2010-03-14 04:44:19

标签: sql

我想显示仅为10及以上的值的结果

select  name, count(*) from actor
join casting on casting.actorid = actor.id
where casting.ord = 1
group  by name
order by 2 desc

将返回此信息:

name    count(*)
Sean Connery    19
Harrison Ford   19
Robert De Niro  18
Sylvester Stallone  18

但我想返回只有10以上的count(*)值

我该怎么做?有吗?

4 个答案:

答案 0 :(得分:3)

HAVING COUNT(*)>10

答案 1 :(得分:2)

试试这个

select  name, count(*) from actor
join casting on casting.actorid = actor.id
where casting.ord = 1
group  by name
having count(*)>10
order by 2 desc

答案 2 :(得分:0)

您应该使用having子句。

select  name, count(*) from actor
join casting on casting.actorid = actor.id
where casting.ord = 1
group  by name
having count(*) > 10
order by 2 desc

答案 3 :(得分:0)

select  name, count(*) from actor
join casting on casting.actorid = actor.id
where casting.ord = 1
group  by name having count(*) > 10
order by 2 desc