Also muss erstmal zustimmen:
am besten wäre es die Tabelle zu normalisieren:
Es gibt jedoch auch eine Lösung über sql, jedoch ist diese Extrem umständlich und lang, da ist es wohl wirklich besser, das ganze über den PHP Code abzufragen:
Hier trotzdem die SQL Lösung:
select sum(anzahl) as vorkommnis from
( select count(*) as anzahl from eintraege
where VWA1 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA2 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA3 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA4 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA5 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA6 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA7 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA8 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA9 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
union all
select count(*) as anzahl from eintraege
where VWA10 in (select zahl from gruppe1)
and eintraege.datum < #01/01/2004#
and eintraege.datum > #01/01/2001#
)
;
Dabei gehe ich davon aus dass die Tabelle mit den Spalten VWA ... eintraege heißt, und die Tabelle mit den Zahlen einer Gruppe gruppe1 (spalte zahl) heißt.
Dies könnte man bei mehrern Gruppen natürlich auch in einer Tabelle zusammenfassen!
Wenn du an der DB nichts extrem ändern willst würde ich dir raten, das ganze wirklich über einfache selects in PHP zu realisieren!
Ich hoffe dass hilft dir etwas weiter!
Gruß
Mr. Database