ingerNorway Posted October 29, 2013 Share Posted October 29, 2013 Hi! I can't figure out this code: SELECT Student.fornavn,etternavn,brukernavn Fag.fagkode, COUNT(Oppgave.nr) AS AntalOppgaver FROM Student,Fag LEFT JOIN Student WHERE Fag.fagkode='DAT1000' = Syntax error , mariadb.......The task text is : The question should get an overview of all students(Here: Student) in a choosen subject(Here:fag) and count how many tasks(here:oppgave) The overview should show sirname(Etternavn)name(Fornavn) username(Brukernavn)and numbers of tasks in the subject(fag)The overview shuld be order by sirname(etternavn)and then on name(fornavn)Any idea? - Look at the E/R attachment Quote Link to comment Share on other sites More sharing options...
ingerNorway Posted October 29, 2013 Author Share Posted October 29, 2013 NEW UPDATE: SELECT Student.fornavn,etternavn,brukernavn Fag.fagkode, COUNT(Oppgave.nr) AS AntallOppgaver FROM Fag INNER JOIN Fagdeltager(ON Student.brukernavn=Fagdeltager.brukernavn) ON Fag.fagkode=Fagdeltager.fagkode WHERE Fag.fagkode='DAT1000' Quote Link to comment Share on other sites More sharing options...
Solution ingerNorway Posted October 29, 2013 Author Solution Share Posted October 29, 2013 THIS SHOULD BE THE RIGHT CODE but it won't work: SELECT etternavn,fornavn,Student.brukernavn, COUNT(nr) AS AntallOppgaver FROM Student INNER JOIN (Fagdeltager INNER JOIN Oppgave ON Fagdeltager.fagkode=Oppgave.fagkode) ON Student.brukernavn=Fagdeltager.brukernavn) WHERE Fagdeltager.fagkode='DAT1000' GROUP BY etternavn,fornavn; Quote Link to comment Share on other sites More sharing options...
ingerNorway Posted October 29, 2013 Author Share Posted October 29, 2013 THIS SHOULD BE THE RIGHT CODE but it won't work: SELECT etternavn,fornavn,Student.brukernavn, COUNT(nr) AS AntallOppgaver FROM Student INNER JOIN (Fagdeltager INNER JOIN Oppgave ON Fagdeltager.fagkode=Oppgave.fagkode) ON Student.brukernavn=Fagdeltager.brukernavn WHERE Fagdeltager.fagkode='DAT1000' GROUP BY etternavn,fornavn; Quote Link to comment Share on other sites More sharing options...
Barand Posted October 29, 2013 Share Posted October 29, 2013 try it without the nested join SELECT etternavn,fornavn,Student.brukernavn, COUNT(nr) AS AntallOppgaver FROM Student INNER JOIN Fagdeltager ON Student.brukernavn=Fagdeltager.brukernavn INNER JOIN Oppgave ON Fagdeltager.fagkode=Oppgave.fagkode WHERE Fagdeltager.fagkode='DAT1000' GROUP BY etternavn,fornavn; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.