kuslahne
kuslahne

Reputation: 730

how to select rows with sum of group in sqlite3?

Let say I have data in sqlite3 like this:

|saleID|data|
|1|a|
|1|b|
|1|c|
|2|x|
|2|y|
|3|t|
|4|x|
|4|y|

I want to count how many times saleID in table appear. How the sql syntax in sqlite to get result like this?

|saleID|count|
|1|3|
|2|2|
|3|1|
|4|2|

Thanks for coder..

Upvotes: 1

Views: 160

Answers (3)

Daniel Brockman
Daniel Brockman

Reputation: 19270

SELECT saleID, COUNT(*) FROM YourTable GROUP BY saleID

Upvotes: 0

Austin Salonen
Austin Salonen

Reputation: 50225

select saleID, count(1) as [count]
from sales
group by saleID

Upvotes: 1

BizApps
BizApps

Reputation: 6130

you just need to use group by:

select saleID,COUNT(data) from Table group by salesID

Regards

Upvotes: 0

Related Questions