2010-03-14 43 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