0

Hi I'm having trouble with a subquery and really need some help.
I'm trying to count to count the number of beats sold by a particular producer.

So the first thing I did was SELECT all the beats sold by that producer so I wrote the code

select name, production_no
from beats
where availability = 'Sold'
and p_staffid = 1;

'p_staffid' is the id number for the particular producer and the 'production_no' is the primary key for the beat itself. I have tested this code and it works perfectly.

But how do I count the results?

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by darkagn
1

The COUNT function will return the number of rows returned by the query which is what I think you are trying to do. The COUNT function requires a column to count as a parameter, so your query will look something like this:

select COUNT(name) as number_sold
from beats
where availability = 'Sold'
and p_staffid = 1;
Votes + Comments
Exactly what I needed.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.