请教一条SQL server 语句.
来源:百度知道 编辑:UC知道 时间:2024/05/26 08:58:40
主键表 用户信息 ID(PK)
外键表 用户发表文章 ID(FK)
我想知道它发了多少篇文章。
外键表 用户发表文章 ID(FK)
我想知道它发了多少篇文章。
selct t1.id,t1.username, count(*) from t1 inner join t2 on t1.id=t2.userid group by t2.userid
其中
t1.id=用户信息表中的用户编号
t2.userid=用户文章表中的用户编号
select * from fk a ,pk b where a.id=b.id
select a.id, a.[username],count(a.id) as num from 主键表 a,外键表 b where a.id=b.id group by a.id,a.[username]
select count(*) from idpk,idfk where pk=fk
select A.[用户名],count(B.ID) as [发表数量] from [用户信息] A,[用户发表文章] B
where A.ID=B.ID
group by A.[用户名]