读书人

多表查询统计 送分,该怎么解决

发布时间: 2012-01-14 20:02:35 作者: rapoo

多表查询统计 送分
2个表A B
A表字段 A_id name tel
B表字段 B_id A_id home

假设:A表
1 'sf ' '123 '
2 'sd ' '234 '
3 'bf ' '345 '

B表
1 1 'a '
2 1 'x '
3 1 '4 '
4 2 '3 '

期待查询结果:
name A_id tel count (计算B表里有多少条值)
'sf ' 1 123 3
'sd ' 2 234 1
'bf ' 3 345 0


学习中,请教了,谢谢大家帮忙


[解决办法]
select A.*,(select count(*) from B where A.A_id=B.A_id) as [count]
from A

读书人网 >SQL Server

热点推荐