Jump to content

SQL. SELECT AND COUNT


ingerNorway
Go to solution Solved by ingerNorway,

Recommended Posts

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 :)post-165326-0-83988300-1383042460_thumb.gif

Link to comment
Share on other sites

  • Solution

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;
Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.