Doppelte Aggregat-Funktion möglich???? max(count(..))

Wollte mal wissen ob es Umwege gibt max(count(…)) auszuführen???

Bekomme dann immer die Meldung:

ERROR: aggregate function calls may not be nested

Unter ORACLE würde es gehen und PostgeSQL???

Hallo raptor0,

Interesante Frage! count() liefert die Anzahl der selektierten Zeilen (auch unter ORACLE). Mehr gibt es leider nicht, auch nicht weniger. Wieviel Zeilen willst Du denn mit max(count(…)) noch erhalten?

Und die Fehlermeldung ist doch auch eindeutig: beide Funktionen sind “aggregate function”.



mfg

fristo

Tachchen,…

Habe folgenden Tabelleninhalt:

hostname officeproduct officeprogram insertdate

xxxxxxx Office2000 Outlook 09.06.2006
xxxxxxx Office2003 Access 09.06.2006
xxxxxxx Office2003 Excel 09.06.2006
xxxxxxx Office2003 Outlook 09.06.2006
xxxxxxx Office2003 PowerPoint 09.06.2006
xxxxxxx Office2003 Visio 09.06.2006
xxxxxxx Office2003 Word 09.06.2006
xxxxxxx Office97 Outlook 09.06.2006

Mit diesem Query:

select hostname,officeproduct,count(officeproduct)
from officeproduct
group by hostname,officeproduct
having hostname ilike’xxxxxxx’

bekomme ich folgendes Ergebnis:

hostname officeproduct count

xxxxxxx Office97 1
xxxxxxx Office2000 1
xxxxxxx Office2003 6

Ich will/wollte nur die Ausgabe bekommen, wo er am meisten gezählt hat. Mit max(count(…)) würde es gehen, wenn es ORACLE wäre…

MfG

raptor0

Hallo raptor0,

wenn Du bei der Anfrage sofort alle Information lieferst, ist es wesentlich einfacher Dir einen Tip zu geben, als wenn Du nur Fragmente des Codes lieferst.

Versuch es mal mit den folgenden Code

select          hostname,
                officeproduct,
                count(officeproduct) as _count
from            officeproduct
group by        hostname,
                officeproduct
having          hostname ilike'xxxxxxx'
order by        _count desc
limit           1;

mfg

fristo

Tachchen fristo,

konnte das Problem auf eine andere Weise lösen, denn es kam noch ein anderes Problem dazu. Was ist, wenn auf einem PC verschiedene Office Versionen installiert sind(97,2003,…)???
Daraufhin habe ich noch eine Zusatztabelle angelegt, wo drin steht wieviele Officekomponenten einer Office Version auf einem PC installiert sind.
Somit kam ich auf folgenden Query:

select *
from officeproduct
where officeproduct in (
select officeproduct
from officecount
where counter >1 and hostname ilike’Fat%’)
order by officeproduct,officeprogram

Auf das “counter >1” kam ich aus dem Grunde, da in der Registry verschiedene Version stehen, die aber nicht installiert sind.

MfG
raptor0

Vielleicht etwas unkonventionell:

select hostname,officeproduct,count&#40]

Weiß jetzt nur nicht, ob das wirklich funktioniert.... :?