0

I have a table in mysql and I want this output:

HNSHAK  MOBILE COMPUTING =13
HNSHAK  STORAGE           =2   

the product group will change each time I execute.

Table:

Productgroup    Created By
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
STORAGE             HNSHAK
MOBILE COMPUTING    HNSHAK
STORAGE             HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK
MOBILE COMPUTING    HNSHAK

2 Answers 2

1

Your query should be this way:

SELECT `Created By`, ProductGroup, COUNT(*) `Count`
FROM tablename
GROUP BY `Created By`, ProductGroup;

using a GROUP BY Created_By, ProductGroup and the aggregate function COUNT.

This will give you:

Created By  ProductGroup           Count
HNSHAK      MOBILE COMPUTING        13
HNSHAK      STORAGE                 2
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT `Created_By`, `Productgroup`, COUNT(`Productgroup`)
FROM `table_name`
GROUP BY `Productgroup`

You should use GROUP BY here. You should also keep in mind that if all of the values in Created By are not same (like one of them is, say, COMPANY1) then either you want to ignore the Productgroup and select first value of Productgroup that appears in the table or you'll have multiple rows of a Productgroup for each _manufacturer. To achieve the latter, you'll use GROUP BY this way

GROUP BY `Created_By`, `Productgroup`

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.