?
Solved

How to Filter a Count

Posted on 2009-02-08
2
Medium Priority
?
308 Views
Last Modified: 2012-06-21
I can list the count for a specific condition.

I need to list only those rows where the count is greater than a specified amount.
The following statement returns the symbolID and the number of increases within a given date range.
SymbolID     Increases
1589      16  
5834      10  
7162      15  
2917      8
1566      14  

This is the list I need:
1589      16
7162      15
1566      14

I need to list only increases greater than 10.

In Psuedocode:

SELECT SymbolID
, Count(*) AS Increases  
FROM StockHist
WHERE
ClosePrice >=ClosePricePrev
AND QuoteDate >= '2009-01-05'
AND QuoteDate <= '2009-02-04'
GROUP BY SymbolID
WHERE Increases > 10

Any ideas would be appreciated.


SELECT SymbolID 
, Count(*) AS Increases  
FROM StockHist 
WHERE 
ClosePrice >=ClosePricePrev 
AND QuoteDate >= '2009-01-05' 
AND QuoteDate <= '2009-02-04'
GROUP BY SymbolID

Open in new window

0
Comment
Question by:Dovberman
2 Comments
 
LVL 9

Accepted Solution

by:
jamesgu earned 1000 total points
ID: 23583891
this
SELECT SymbolID 
, Count(*) AS Increases  
FROM StockHist 
WHERE 
ClosePrice >=ClosePricePrev 
AND QuoteDate >= '2009-01-05' 
AND QuoteDate <= '2009-02-04'
GROUP BY SymbolID
having count(*) > 10

Open in new window

0
 

Author Closing Comment

by:Dovberman
ID: 31544219
That was almost too easy.
Thanks for the quick response. I had spent one hour on this. It saved me a lot of time.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question