Ich habe drei Tabellen und ich möchte dies: Für jede Fähigkeit, begann im Jahr 2016 und Teil von mindestens zwei Training Packs und vervollständigt mit einem Ergebnis zwischen 12 und 17, Liste der Qualifikation ID, seine Kategorie, das Niveau, die Anzahl der Trainingspakete, die ein Teil davon sind, und seine durchschnittliche Punktzahl.Aggregat-Funktion in SQL
Ich schrieb den Code unten, aber es gibt ein Problem, wenn ich den Mittelwert und Summe auswählen.
select SKILLNUM , SKCATEGORY , SKLEVEL , count(TPID)
from (trainingpack t join Is_part_of i on t.TPID=i.TPID join skill s on i.SKILLNUM=s.SKILLNUM)
where STARTINGDATE like '%2016' and COMPLDATE is not null and score between 12 and 17
and (SKILLNUM) in (
select is_part_of.SKILLNUM
from is_part_of
group by SKILLNUM
having count(TPID) >=2);
Auch habe ich versucht, diesen Code
select SKILL.SKILLNUM , SKILL.SKCATEGORY , SKILL.SKLEVEL ,count(IS_PART_OF.TPID),sum(IS_PART_OF.SCORE)
from SKILL,TRAININGPACK,IS_PART_OF
where TRAININGPACK.STARTINGDATE like '%2016' and IS_PART_OF.COMPLDATE is not null and IS_PART_OF.score between 12 and 17
and IS_PART_OF.TPID=TRAININGPACK.TPID and IS_PART_OF.SKILLNUM=SKILL.SKILLNUM and (is_part_of.SKILLNUM) in (
select is_part_of.SKILLNUM
from is_part_of
group by SKILLNUM
having count(TPID) >=2);
Beispieltabellen anzeigen – DCR
Zuerst herausfinden, welche RDBMS Sie verwenden. Dann siehe http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-very-simple-sql- Abfrage – Strawberry
Möglicherweise müssen Sie die anderen Spalten in der Gruppierung nach Klausel hinzufügen. also GROUP BY SkillNum, SkCategory, SkLevel –