sqlserver 连接查询的问题,a表无重复记录,与b表中的记录为1对N关系,如何在查得a表信息时统计b表记录数


第一种
select t1.id,
t1.name,
t1.age,
(select count(1) from b t2 where t1.id = t2.id) filecount
from a t1
第二种
select t1.id, t1.name, t1.age, t2.filecount
from a t1
left join (select id, count(1) filecount from b group by id) t2
on t1.id = t2.id

posted @ 2015-05-30 11:38  凄风  阅读(191)  评论(0编辑  收藏  举报