开发者

how to select rows with sum of group in sqlite3?

开发者 https://www.devze.com 2023-04-08 09:38 出处:网络
Let say I have data in sqlite3 like this: saleID|data| |1|a| |1|b| |1|c| |2|x| |2开发者_如何学C|y| |3|t|

Let say I have data in sqlite3 like this:

|saleID|data|
|1|a|
|1|b|
|1|c|
|2|x|
|2开发者_如何学C|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..


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


you just need to use group by:

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

Regards


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号