Sql:获取数字数组“id”列
我有这张桌子:Sql:获取数字数组“id”列,sql,Sql,我有这张桌子: id idR name check 1 id1 John true 2 id1 Abe false 3 id2 Ernest false 4 id3 Alice false 5 id3 Alf false 6 id3 Ralf false 7 id4 Danny false 8 id5 Alex false 9 id5 Nicolas false 10 id7 Dan
id idR name check
1 id1 John true
2 id1 Abe false
3 id2 Ernest false
4 id3 Alice false
5 id3 Alf false
6 id3 Ralf false
7 id4 Danny false
8 id5 Alex false
9 id5 Nicolas false
10 id7 Dan true
我需要得到一个整数数组,它告诉我每个idR的值与它们的值相似。
例如,我会得到如下结果:
2,1,3,1,2,0,1
试试这个:
select idR,count (distinct id )as count from table group by idR;
试试这个
select idR,count(*) as count_idR from table group by idR;
但是对于idR 6,如果您想要零,那么您必须指定一个条件,即在我们可以进行查询之前,您想要获取计数的数字,其余的上述数字将提供所有当前计数