请各位大侠帮我一个忙:在下感激不尽!具体问题如下:我有个表:BrandJoinId memberid BrandListId BrandDetailsId Ip JoinTime
1 199625 1 2 192.168.1.1 2009-8-11 11:59:42
2 199624 1 5 192.168.1.1 2009-8-11 12:04:05
3 199623 1 2 192.168.1.1 2009-8-12 13:06:08
4 199628 1 7 192.168.1.107 2009-8-12 17:19:59
14 203682 1 10 192.168.1.107 2009-8-13 11:52:56
15 203682 1 9 192.168.1.107 2009-8-13 11:52:56
16 203682 1 7 192.168.1.107 2009-8-13 11:52:56
17 199265 1 6 192.168.1.107 2009-8-17 15:09:39
18 199265 4 27 192.168.1.107 2009-8-17 16:14:41
19 199265 4 26 192.168.1.107 2009-8-17 16:14:41
20 199265 4 25 192.168.1.107 2009-8-17 16:14:41
21 199265 4 24 192.168.1.107 2009-8-17 16:14:41
22 199265 4 23 192.168.1.107 2009-8-17 16:14:41
23 199265 4 22 192.168.1.107 2009-8-17 16:14:41
24 199265 4 21 192.168.1.107 2009-8-17 16:14:41
25 206364 2 13 192.168.1.107 2009-8-17 17:41:42
26 206364 2 16 192.168.1.107 2009-8-17 17:41:42
27 206364 3 29 192.168.1.107 2009-8-17 17:42:13
28 206364 3 32 192.168.1.107 2009-8-17 17:42:13
29 162268 2 16 192.168.1.107 2009-8-17 18:14:42
30 162268 2 17 192.168.1.107 2009-8-17 18:14:42我想写个SQL得到以下结果不知道这样的SQL 怎么写。BrandListId BrandListCount
1 8
4 7
2 4
3 2意思就说表中 BrandListId 为 1的有8个,BrandListId 为4 的有7个,BrandListId 为2 的有4个,BrandListId 为3的有2个。不知道各位大侠能不能明白,谢谢。在下SQL 初级选手!
1 199625 1 2 192.168.1.1 2009-8-11 11:59:42
2 199624 1 5 192.168.1.1 2009-8-11 12:04:05
3 199623 1 2 192.168.1.1 2009-8-12 13:06:08
4 199628 1 7 192.168.1.107 2009-8-12 17:19:59
14 203682 1 10 192.168.1.107 2009-8-13 11:52:56
15 203682 1 9 192.168.1.107 2009-8-13 11:52:56
16 203682 1 7 192.168.1.107 2009-8-13 11:52:56
17 199265 1 6 192.168.1.107 2009-8-17 15:09:39
18 199265 4 27 192.168.1.107 2009-8-17 16:14:41
19 199265 4 26 192.168.1.107 2009-8-17 16:14:41
20 199265 4 25 192.168.1.107 2009-8-17 16:14:41
21 199265 4 24 192.168.1.107 2009-8-17 16:14:41
22 199265 4 23 192.168.1.107 2009-8-17 16:14:41
23 199265 4 22 192.168.1.107 2009-8-17 16:14:41
24 199265 4 21 192.168.1.107 2009-8-17 16:14:41
25 206364 2 13 192.168.1.107 2009-8-17 17:41:42
26 206364 2 16 192.168.1.107 2009-8-17 17:41:42
27 206364 3 29 192.168.1.107 2009-8-17 17:42:13
28 206364 3 32 192.168.1.107 2009-8-17 17:42:13
29 162268 2 16 192.168.1.107 2009-8-17 18:14:42
30 162268 2 17 192.168.1.107 2009-8-17 18:14:42我想写个SQL得到以下结果不知道这样的SQL 怎么写。BrandListId BrandListCount
1 8
4 7
2 4
3 2意思就说表中 BrandListId 为 1的有8个,BrandListId 为4 的有7个,BrandListId 为2 的有4个,BrandListId 为3的有2个。不知道各位大侠能不能明白,谢谢。在下SQL 初级选手!
memberid AS BrandListId
,COUNT(BrandListId )AS BrandListCount
FROM TB GROUP BY memberid
select BrandListId,BrandListCount=count(1) from BrandJoin group by BrandListId
memberid AS BrandListId ,COUNT(BrandListId )AS BrandListCount
FROM TB
GROUP BY memberid
memberid as BrandListId,
BrandListId,
count(1) as BrandListCount
from
BrandJoin
group by
BrandListId
memberid as BrandListId,
count(1) as BrandListCount
from
BrandJoin
group by
memberid
order by
BrandListCount desc