Thema: SQL Count

Einzelnen Beitrag anzeigen

angos

Registriert seit: 26. Mai 2004
Ort: Rheine
549 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: SQL Count

  Alt 21. Nov 2012, 07:52
Möglicherweise so (ungetestet):

Code:
SELECT
  feld1, feld2, feld3, f1_count.c, f2_count.c, f3_count.c
FROM tab

LEFT OUTER JOIN (
  SELECT feld1, COUNT(*) AS c
  FROM tab
  GROUP BY feld1
) AS f1_count ON (tab.feld1 = f1_count.feld1)

LEFT OUTER JOIN (
  SELECT feld2, COUNT(*) AS c
  FROM tab
  GROUP BY feld2
) AS f2_count ON (tab.feld2 = f1_count.feld2)

LEFT OUTER JOIN (
  SELECT feld3, COUNT(*) AS c
  FROM tab
  GROUP BY feld3
) AS f3_count ON (tab.feld1 = f1_count.feld3)
Ansgar
  Mit Zitat antworten Zitat