I do not want the max values of c or so.
I want "two" records (or one with those values) which contain fk, c and HAVE THE SAME datum.
Then you can't use having. Having only work with group by.
And in Firebird you can only group by over all Unique columns (unlike MySQL).
You could have spared us all a lot of trouble if you mentioned your expected result in your other topic.
Also... you didn't provide a dataset again.
I've created one here:
https://dbfiddle.uk/1quhN-EbIf you want all records individual you probably need to use a SELECT as a field.
Someone can probably restructure this to a JOIN or WITH but then you see that's it easier for us if you give us a small datasample in dbfiddle.
And here we come across one of the biggest uglyness in Firebird... you can't address a field by its alias in the WHERE clause. You need to repeat the complete field (the subselect in this case) in the WHERE again to get the count(*). That's probably why this can be better written with a JOIN or WITH. But I'm not going to unless you are more clear if this is the actual required result

SELECT ID_KURSZEILE, DATUM, FK_KONTRAKT, C,
(
SELECT COUNT(*)
FROM TBKURSZEILEN B
WHERE B.DATUM=A.DATUM AND (B.FK_KONTRAKT = '5' OR B.FK_KONTRAKT = '6')
) AS X
FROM TBKURSZEILEN A
WHERE (
SELECT COUNT(*)
FROM TBKURSZEILEN B
WHERE B.DATUM=A.DATUM AND (B.FK_KONTRAKT = '5' OR B.FK_KONTRAKT = '6')
)=2
AND (A.FK_KONTRAKT = '5' OR A.FK_KONTRAKT = '6')
ORDER BY DATUM, ID_KURSZEILE