[ Fnatic @ 07.11.2012. 21:23 ] @
Pozdrav svima treba mi pomoc oko jednog zadatka .
Izračunati prosek ocena po ID Predmeta
Prikazati u rezultat kolonu PredmetID i sumu ocena, grupisati po koloni PredmetID iz tabele StudentPredmet
Izračunati prosek ocena za svakog studenta

Selektovati kolone: StudentPredmet.StudentID, Student.Ime, Student.Prezime, Ocena
Koristeći tabele: dbo.StudentPredmet, dbo.Student
Rezultat prikazati desc nad kolonom StudentPredmet.StudentID.

Znam da napravim Tabele i poglede ali ne znam da izracunam sto se trazi .
SQL Management Studio koristim.
[ Dusan Kondic @ 08.11.2012. 11:31 ] @
Možda nešto ovako:
Code:

SELECT dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon, 
dbo.StudentPredmet.PredmetID, AVG(dbo.StudentPredmet.Ocena) AS SrednjaOcena
FROM dbo.Student INNER JOIN dbo.StudentPredmet ON dbo.Student.SudentID = dbo.StudentPredmet.StudentID
GROUP BY dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon, dbo.StudentPredmet.PredmetID
ORDER BY dbo.Student.SudentID DESC
[ Fnatic @ 08.11.2012. 16:32 ] @
Hvala na pomoci , znacu sad da uradim .




Svako dobro
[ VincentValentine @ 28.02.2015. 11:03 ] @
Citat:
Dusan Kondic:
Možda nešto ovako:
Code:

SELECT dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon, 
dbo.StudentPredmet.PredmetID, AVG(dbo.StudentPredmet.Ocena) AS SrednjaOcena
FROM dbo.Student INNER JOIN dbo.StudentPredmet ON dbo.Student.SudentID = dbo.StudentPredmet.StudentID
GROUP BY dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon, dbo.StudentPredmet.PredmetID
ORDER BY dbo.Student.SudentID DESC






Column 'dbo.StudentPredmet.StudentID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
[ Dusan Kondic @ 28.02.2015. 11:50 ] @
Pišem napamet, ali ovo bi trebalo da radi:
Code:

SELECT dbo.Student.StudentID, dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon, 
MAX(dbo.StudentPredmet.PredmetID) AS PredmetID, AVG(dbo.StudentPredmet.Ocena) AS SrednjaOcena
FROM dbo.Student INNER JOIN dbo.StudentPredmet ON dbo.Student.SudentID = dbo.StudentPredmet.StudentID
GROUP BY dbo.Student.StudentID, dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon
ORDER BY dbo.Student.StudentID DESC
[ VincentValentine @ 28.02.2015. 14:05 ] @
select dbo.Student.Ime, dbo.Student.Prezime,
avg(dbo.StudentPredmet.Ocena) as srednjaOcena
from dbo.Student INNER JOIN dbo.StudentPredmet on dbo.Predmet.PredmetID = dbo.StudentPredmet.PredmetID
group by dbo.Student.Ime, dbo.Student.Prezime
order by dbo.Student.Ime DESC

gde gresim kada racunam prosecnu po ocenuku
[ plague @ 28.02.2015. 15:18 ] @
Join uslov ne valja:
Code (sql):

INNER JOIN dbo.StudentPredmet ON dbo.Student.StudentID = dbo.StudentPredmet.StudentID
 
[ VincentValentine @ 28.02.2015. 16:25 ] @
Izračunati prosek ocena po ID Predmeta
Prikazati u rezultat kolonu PredmetID i sumu ocena, grupisati po koloni PredmetID iz tabele StudentPredmet
Po predmetuID bi trebalo da bude ovako, ali opet prijavljuje gresku


SELECT dbo.Student.StudentID, dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon,
SUM(dbo.StudentPredmet.Ocena) AS SumaOcena, AVG(dbo.StudentPredmet.Ocena) AS SrednjaOcena
FROM dbo.Student INNER JOIN dbo.ProfesorPredmet ON dbo.Predmet.PredmetID = dbo.ProfesorPredmet.PredmetID
GROUP BY dbo.Student.StudentID, dbo.Student.Ime, dbo.Student.Prezime, dbo.Student.BrojIndexa, dbo.Student.Telefon
ORDER BY dbo.Predmet.PredmetID DESC
[ VincentValentine @ 28.02.2015. 17:27 ] @

ok, ovaj jedan sam uspeo. ovo je prosek ocena po studentId desc

select dbo.Student.Ime, dbo.Student.Prezime, dbo.StudentPredmet.StudentID,
avg(dbo.StudentPredmet.Ocena) as srednjaOcena
from dbo.Student INNER JOIN dbo.StudentPredmet ON dbo.Student.StudentID = dbo.StudentPredmet.StudentID
group by dbo.Student.Ime, dbo.Student.Prezime, dbo.StudentPredmet.StudentID
order by dbo.StudentPredmet.StudentID DESC


jos prosek ocena po ID Predmeta
Prikazati u rezultat kolonu PredmetID i sumu ocena, grupisati po koloni PredmetID iz tabele StudentPredmet
koristeci
tabele dbo.StudentPredmet, dbo.Student
tabele dbo.StudentPredmet, dbo.Student
[ Dusan Kondic @ 02.03.2015. 12:31 ] @
Ako sam dobro razumeo, potreban ti je prosek ocena svakog studenta iz svakog predmeta. U tom slučaju samo u GROUP BY klauzulu dodaj i polje PredmetID a pošto ćeš siguno želeti da prikažeš i naziv predmeta, JOIN-uj tabelu sa predmetima i dodaj naziv predmeta u SELECT i u GROUP BY klauzulu.
Čemu služi suma ocena?
[ Cat23 @ 06.03.2015. 11:58 ] @
Pozz svima.
Sto se mene tice ovo je resenje za prosek ocena po ID Predmetu,stim sto on trazi i da se u novoj kolini prikaze suma pa sam i to ubacila.

select dbo.Predmet.PredmetID,
avg(dbo.StudentPredmet.Ocena) as ProsekOcena,
SUM(dbo.StudentPredmet.Ocena) as SumaOcena
from dbo.Predmet inner join dbo.StudentPredmet
on dbo.Predmet.PredmetID = dbo.StudentPredmet.PredmetID
group by dbo.Predmet.PredmetID

Sto se tice drugog zadatka ja sam napravila ovako

select dbo.StudentPredmet.StudentID,dbo.Student.Ime,dbo.Student.Prezime,
AVG(dbo.StudentPredmet.Ocena) as ProsekStudenta
from dbo.Student inner join dbo.StudentPredmet
on dbo.Student.StudentID=dbo.StudentPredmet.StudentID
group by dbo.StudentPredmet.StudentID,dbo.Student.Ime,dbo.Student.Prezime
order by dbo.StudentPredmet.StudentID desc