在select语句sql中分组 [英] group by in select statement sql

查看:165
本文介绍了在select语句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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆