select , count ,group by ????
表A: id,name,nick
表B: news_id,name,title,body
A为用户表,B为信息表
需要的结果:查出每个用户在B表中对应的信息条数
问题点数:20、回复次数:8Top
1 楼junguo(junguo)回复于 2002-12-09 13:29:19 得分 3
select count(*) from b group by news_id having a.id = b.news_idTop
2 楼shenanigan(宝宝)回复于 2002-12-09 13:31:10 得分 3
select count(*) from a,b group by news_id having a.id = b.news_id
Top
3 楼harryyang(crane)回复于 2002-12-09 13:31:44 得分 2
select count(*) from b group by news_id having a.id = b.news_id
Top
4 楼heroqxn(Brook)回复于 2002-12-09 13:41:02 得分 0
如果我想要的结果是这样的改怎样写?
a.id a.name a.nick counter
------------------------------------------------
1 qqq qqqqqq 213212
2 rtrret fgdfg 132132
3 42342 3565 65465465
-------------------------------------------------
counter是对应每个用户在B表中的信息条数Top
5 楼harryyang(crane)回复于 2002-12-09 13:43:53 得分 2
用left join可以吧...
select id,nam,nich form a left join 上面的語句
我沒做測試..不好用在說!Top
6 楼CoolSlob()回复于 2002-12-09 13:44:59 得分 5
select a.id, a.name, a.nick, count(*) as counter
from a, b
where a.name=b.name
group by a.id, a.name, a.nick
order by a.idTop
7 楼CoolSlob()回复于 2002-12-09 13:45:47 得分 5
也可以用join来实现:
select a.id, a.name, a.nick, count(*) as counter
from a inner join b on a.name=b.name
group by a.id, a.name, a.nick
order by a.id
Top
8 楼heroqxn(Brook)回复于 2002-12-09 14:06:30 得分 0
多谢大家,我实在是分不多了,要不然多给大家些,谢谢Top
相关问题
- Select sz,count(*) as total from l_Zjgcsshspb group by sz
- select a,count(*) as b from c group by a后怎样再得到总count(*)
- sql="select office ,count(*) as num1 from bank Group by office order by num1 desc "
- select author,count(*) as record from hfluntan order by record desc group by author limit 0,20
- select substring(sendtime,1,8) ,count(*) from (select sendtime c from hasms_mo) group by substring(sendtime,1,8) ;为什么不能做?
- 搞错了分数,select substring(sendtime,1,8) ,count(*) from (select sendtime c from hasms_mo) group by substring(sendtime,1,8) ;为
- SELECT COUNT(*)FORM(SELECT a,b FROM t_TABLE GROUP BY a,b )是错误的,高手赐教!!!!!急
- group by和count问题
- select max(count(*)) from table group by aa这个意思的语句该怎么样写?
- group by和count问题2




