0

Running this sql:

SELECT
    user_id,
    base_item
FROM
    items
WHERE
    base_item = "202"

gives me this http://prntscr.com/9gwwxq However, how do i expand the MYSQL query to add up the amount of 202 base_items a user_id has. e.g user_id 41 has 6.

1
  • No of item count against user? Commented Dec 21, 2015 at 19:19

3 Answers 3

1

This should give you the number of “202” base_items per user ID:

SELECT
    user_id,
    COUNT(*)
FROM
    items
WHERE
    base_item = "202"
GROUP BY user_id
Sign up to request clarification or add additional context in comments.

Comments

0

try it:

SELECT
    user_id,
    count(base_item) as c
FROM
    items
WHERE
    base_item = "202"
group by
    user_id

1 Comment

No need to put base_item in the count function, just use count(*).
0

Try this to count of similar base_item

SELECT
    user_id, 
    base_item, count(*) as user_no
FROM
    items
WHERE
    base_item = "202" 
GROUP BY user_id

1 Comment

gives me this result prntscr.com/9gx0jp . I want the results to be like user_id 2 has 10 or the number they actually have.

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.