Reputation: 163
SELECT items.id,
items.category,
COUNT(*)
FROM items
GROUP BY items.id,
items.category
I want to display how many items in each category.
For example,
category 1 - 6
category 2 - 7
category 3 - 4 ...
Please help me! I try this request and show me all the items with category :/
Upvotes: 3
Views: 11197
Reputation: 21
Please use 'distinct'
SELECT distinct items.category,
COUNT(*) AS Count
FROM items
GROUP BY items.category
to get the correct count for each unique category
Upvotes: 2
Reputation: 45
Try this...
select items.category,COUNT(items.COUNT(*)) from items Group By items.category;
Upvotes: 1
Reputation: 3347
Try this...
SELECT items.category,
COUNT(*) AS Count
FROM items
GROUP BY items.category
Upvotes: 3
Reputation: 50163
If, you want to display count based of category then use group by
clause with colum category
SELECT category, count(*) as Noofitems
FROM items i
GROUP BY category;
Tiny word of advice :- Use table alise that could be easy to follow and read/wrire
Upvotes: 1