DataSet增加列填充数据问题,麻烦高手指点!
一个留言板,两个表,message和response,通过m_Id字段关联
想在ds.tables[ "Message "]增加一列huifu显示每个主题的回复数
ds.tables[ "Message "]表如下:
m_id m_user m_subject
1 Admin 主题1
2 Test 主题2
3 YY 主题3
response表结构如下:
r_id context m_id
1 回复1 1
2 回复2 1
3 回复3 2
4 回复4 1
5 回复5 3
6 回复6 2
想将ds.tables[ "Message "]表最后的结构变成如下形式:
m_id m_user m_subject huifu(此主题被回复的次数)
1 Admin 主题1 3
2 Test 主题2 2
3 YY 主题3 1
麻烦各位指点,30分,谢谢!
[解决办法]
select m_id, m_user, m_subject,
(select count(1) from response b where b.m_id=b.m_id) as huifu
from message a
[解决办法]
select ta.m_id, ta.m_user, ta.m_subject,
(select count(tb.m_id) from response tb where tb.m_id=ta.m_id) as huifu
from ta