Return results only if there are enough records

3891 views sql
6

Thanks in advance for your replies, this is a 2-part question.

The Database would be called: "Production" The Table would be called: "FruitHistory"

Sample Data:

enter image description here

Is there a way to query this data such that it will only return results that have at least 3 day's worth of data (as an example).

Ex: The query returns Tony's, David's and Aaron's records but not Bern's


Part2:

Building on Part1's rule but now only returning 3 days worth of data at all

Ex: The query returns 11/3-11/5 for Tony and Aaron and all of David's data but still not Bern's.

Thanks!

answered question

What SQL technology are you using?

There are no Aaron rows in your sample data.

Also, the second column does not appear to be any date format I have seen before. It looks like maybe you copied this out of Excel, but the formatting got messed up.

which database? is there a date field?

MySQL, SQL Server, Oracle, PostgreSQL, etc, etc, etc??

1 Answer

6

First part:

SELECT Name, Count(*)
FROM table
GROUP BY Name
HAVING Count(*)>2

Second Part:

SELECT *
FROM table
WHERE Name IN (SELECT Name
FROM table
GROUP BY Name
HAVING Count(*)>2)

posted this

Have an answer?

JD

Please login first before posting an answer.