Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Mehrere Counts ausführen (https://www.delphipraxis.net/96914-mehrere-counts-ausfuehren.html)

DGL-luke 2. Aug 2007 10:34

Re: Mehrere Counts ausführen
 
Okay, schau ich mir an. Gut, dass ich mitm Kreuz keine Probleme hab :mrgreen:

EDIT:

guuuutttt....

SQL-Code:
SELECT COUNT(CASE [is_main_cat] WHEN 1 THEN * ELSE 0 END) as maincount, COUNT(CASE [is_main_cat] WHEN 0 THEN * ELSE 0 END) as seccount FROM ber_catlinks GROUP BY cat_id ORDER BY cat_id ASC
Damit kann ich wohl schonmal die Counts einzeln holen, nehm ich an.

wenn ich das ganze jetzt auf meine query erweitere, muss ich das praktisch nur so splitten:

SQL-Code:
SELECT cats.id as id, cats.parent as parent, cats.name as name, cats.info as info, COUNT(CASE [is_main_cat] WHEN 1 THEN * ELSE 0 END) as maincount, COUNT(CASE [is_main_cat] WHEN 0 THEN * ELSE 0 END)
FROM ber_cats as cats, ber_catlinks as links
WHERE cats.id = links.cat_id
GROUP BY cats.id, cats.parent, cats.name, cats.info
ORDER BY cats.id ASC
Werd gegebenenfalls heut abend nochmal dezent pushen, falls du bis dahin nichtgeantwortet hast ;-)
EDIT: ist auch überhaupt nicht dringend. Werd da vor am sql sowieso nicht weiterarbeiten.

DeddyH 2. Aug 2007 18:52

Re: Mehrere Counts ausführen
 
Hallo,

ich habe das gerade mal unter Firebird probiert (allerdings nur mit wenigen Datensätzen):
SQL-Code:
select cats.id, cats.name, cats.parent, cats.info,
(select count(*) from links where links.is_main_cat = 0 and cats.id = links.cat_id) as Anz_0,
(select count(*) from links where links.is_main_cat = 1 and cats.id = links.cat_id) as Anz_1
from cats
left join links on cats.id = links.cat_id
group by cats.id, cats.name, cats.parent, cats.info
Schau mal, ob das so passt.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:35 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz