Vityata Vityata - 4 months ago 16
SQL Question

SQL - Find not distinct values with two criteria

Pretty much it is easier to show, than to explain:

I have the following table:

enter image description here

The idea is, that I need only the "Objekts", for which I have entered the Datum within the same month.
E.g., "aaa" is needed, because I have data for August twice. "bbb" is not needed, because I have once for August and once for Septermber, which is OK.

This is what I've tried so far:

SELECT objekt,count(*) as counter
FROM tempt_report
GROUP BY objekt
HAVING count(*)>1

But obviously, I do not mention the requirement for the "Datum", and thus I do not get what I want.

Thanks! :)


not sure if I'm missing something! You want >1 of any type in a month of a year

SELECT objekt,year(datum),month(datum),count(*) as counter
FROM tempt_report
GROUP BY objekt, year(datum),month(datum)
HAVING count(*)>1