Two SELECT-Statement Commands Work Alone, But Not Together

I have two select statements that work on their own, but not together.

It:

SELECT MAX(a2.Fachanzahl)
FROM C17_AbfrageBView a2;

works and returns one row with one column with value 2

It:

SELECT a1.PersonID, a1.Vorname, a1.Nachname, MAX(a1.Fachanzahl) Fachanzahl
FROM C17_AbfrageBView a1
GROUP BY a1.PersonID, a1.Vorname, a1.Nachname
HAVING MAX(a1.Fachanzahl) = 2;

works and returns the correct string.

However, this:

SELECT a1.PersonID, a1.Vorname, a1.Nachname, MAX(a1.Fachanzahl) Fachanzahl
FROM C17_AbfrageBView a1
GROUP BY a1.PersonID, a1.Vorname, a1.Nachname
HAVING MAX(a1.Fachanzahl) = (
                              SELECT MAX(a2.Fachanzahl)
                              FROM C17_AbfrageBView a2
                            );

returns nothing (it should return the same string as the previous statement), although the external and internal selection commands work on their own. What is the problem?

Thank!

+4
source share
1 answer

I cannot think of a mechanism in which this will happen. As far as I know, it MAX()does not change the type of the column, except for things like rounding errors or rounding incompatibilities.

, , WHERE, HAVING:

SELECT DISTINCT a1.PersonID, a1.Vorname, a1.Nachname, a1.Fachanzahl
FROM C17_AbfrageBView a1
WHERE a1.Fachanzahl = (SELECT MAX(a2.Fachanzahl)
                       FROM C17_AbfrageBView a2
                      );

MAX() - , .

( , ), . . SELECT DISTINCT GROUP BY . .

+1

Source: https://habr.com/ru/post/1693681/


All Articles