SELECT DATE(A.Inspection_datetime) AS Date,  
  A.Model,  
  COUNT(A.Serial_number) AS Qty,  
  B.Name  
FROM inspection_report AS A  
LEFT JOIN Employee AS B ON A.NIK = B.NIK  
 GROUP BY A.Model, A.Serial_number 

Kris's user avatar

Kris

14.5k7 gold badges58 silver badges65 bronze badges

asked Aug 23, 2010 at 9:27

user428045's user avatar

5

  • A question usually requires a question ;-)

    2010-08-23 09:28:55 +00:00

    Commented Aug 23, 2010 at 9:28

  • Change to do what? Or is there something wrong with it? You might need more columns on the GROUP BY to match the list you're returning (e.g. DATE(A.Inspection_datetime)), and it'd make more sense to COUNT() on a column in table B rather than the column you're grouping on (e.g. B.NIK) though that might not actually be a problem.

    2010-08-23 09:29:23 +00:00

    Commented Aug 23, 2010 at 9:29

  • Click on the parts of the code you want changed with your mouse which will probably be located somewhere near your computer. You will need to then press the corresponding keys on your character entry device to apply the changes in the code. Feel free to use both hands, you don't need to keep hold of the mouse when you are happy with the pointers position on your monitor.

    2010-08-23 09:30:50 +00:00

    Commented Aug 23, 2010 at 9:30

  • Finally a question that really deserves the "not a real question" closing.

    2010-08-23 09:31:17 +00:00

    Commented Aug 23, 2010 at 9:31

  • Some sample data and expected results would be nice too.

    2010-08-23 09:34:14 +00:00

    Commented Aug 23, 2010 at 9:34

1 Answer 1

At a guess (and believe me, I'm guessing)

SELECT DATE(A.Inspection_datetime) AS Date,   
  A.Model,   
  COUNT(A.Serial_number) AS Qty,   
  B.Name   
FROM inspection_report AS A   
LEFT JOIN Employee AS B ON A.NIK = B.NIK   
 GROUP BY A.Model, B.Name   

You need to group by the fields you're not aggregating

answered Aug 23, 2010 at 9:31

Binary Worrier's user avatar

Sign up to request clarification or add additional context in comments.

2 Comments

For bonus points, change the alias for Employee from B to Beat, then you can have a Beat.Nik :)

For mega bonus points, then change nik to root, then you will have a beat.root which is a tasty and healthy vegetable whose promotion can only better the world.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.