2010-03-14 69 views
0

我想显示那些只有10个值和超过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以上的计数(*)的值。

我该怎么做?有?

+0

听起来像是你知道答案已经 - 你尝试了吗? – 2010-03-14 05:03:03

回答

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 
+0

我的记分牌显示为我的答案投票?我的回答有什么问题? – 2010-03-14 04:54:07

+0

wasnt me。这很好 – 2010-03-14 05:47:01

3

是的。

HAVING COUNT(*)>10 
+0

它应该放在哪里? – 2010-03-14 04:46:39

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 
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