I have a table (sales) which has four columns;
id, user_id, product_id, and date_added.
I need to count the number of products with a certain id which have been sold by a user, and also get an overall count of products sold by that user in the current month.
I cant manage to sum the total products. I have;
SELECT user_id, product_id, count(user_id)
FROM sales
WHERE MONTH(date_added) = MONTH(CURRENT_DATE)
GROUP BY user_id, product_id;
how do I sum the total sales for a user, so I can get a percentage of total sales which are a specific product_id?
I expect my output to look something like this;
|----------|----------|----------|----------|
|user_id |product_id|sales |total |
|----------|----------|----------|----------|
|1 |4 |6 |82 |
|2 |4 |3 |121 |
|3 |4 |8 |93 |
|----------|----------|----------|----------|
where total is the total number of sales made by the user.
(Is should mention that I don't need mysql to calculate the percentage - just to get the sum of all product sales)
thanks