0

I have the following database:

Drager ||  Price
----------------
LP     ||  €16
CD     ||  €9 
LP     ||  €21
S      ||  €12

I want to count the "Drager" and make a table that looks like this:

Drager ||  Number  ||  Price
LP     ||  2       ||  €37
CD     ||  1       ||  €9
S      ||  1       ||  €12

My question now is: how can I count all the "dragers"?

I got this query but how can I count them separetaly?:

$query = "SELECT COUNT(Medium) FROM platen";

And how can I get the total price?

I appreciate your help!

2
  • What do you mean count them separately? Commented Jun 23, 2013 at 18:13
  • So I can count how many LP's there are in Medium and how many cd's there are etc so I get like LP : 2, CD : 1, S : 1 back Commented Jun 23, 2013 at 18:14

2 Answers 2

3

Should be as simple as:

SELECT  Drager
      , COUNT(*) AS Number_of_Dragers
      , SUM(price) AS Price_of_Dragers
FROM    your_table
GROUP BY Drager 
Sign up to request clarification or add additional context in comments.

Comments

1

I think this is what your looking for;

$query = "SELECT drager, COUNT(drager),SUM(price) FROM platen GROUP BY drager";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.