Home > database >  SQL Multiple return values
SQL Multiple return values

Time:03-30

I have a table, Test with one column, ItemNo as an integer. I want to count the number of equal ItemNo's. Getting the count one at a time is easy:

SELECT COUNT(ItemNo) FROM Test WHERE ItemNo=1;

which returns 3. How can I have all results (in an array or similar) in one go?

The table Test with the ItemNo column:

1
1
1
2
2
3
3
3
3
4
4

CodePudding user response:

SELECT ItemNo,Count(*)as cntt
FROM your_table
GROUP BY ItemNo

CodePudding user response:

select ItemNo, count(1) from Test group by ItemNo;

CodePudding user response:

SELECT ItemNo, COUNT(*) item_count FROM Test GROUP BY ItemNo ORDER BY ItemNo;
  • Related