在select语句sql中分组 [英] group by in select statement sql
问题描述
我在表格中有3列(id,ParentDeviceId,ResellerId,IsPurchase)。可以有对应于相同/不同势resellerid和购买的parentId的2的ID。
即
ID ParentDeviceId ResellerId IsPurchase
---------------------------------------------- --------
1 100 580 1
2 100 580 0
3 100 600 0
现在我想编写一个select语句,它将获得具有相同Ispurchase和parentdevice的行。 ResellerId值是不相关的。
通过Ispurchase从表组SELECT COUNT(*),parentdevice
会给你具有相同Ispurchased父设备的所有行的计数。
Hi,
I have 3 columns (id,ParentDeviceId,ResellerId,IsPurchase) in a table. There can be 2 id corresponding to a parentid of same/diffrent resellerid and purchase.
i.e
ID ParentDeviceId ResellerId IsPurchase
------------------------------------------------------
1 100 580 1
2 100 580 0
3 100 600 0
Now i want to write a select statement that will get me rows that have same Ispurchase and parentdevice . ResellerId value is irrelevant.
select count(*) from table group by Ispurchase, parentdevice
will give you a count of all rows that have the same Ispurchased parentdevice.
这篇关于在select语句sql中分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!