我有一对父子关系的表。我想将一个sum函数应用到子表的一列,并以父表的所有数据为例返回它。查询的在另一个表中求和值的MySQL查询
Parent_table
ID, Date, Title
Child_table
ID, another_id, column_to_sum
//(ID is foreign key pointing to Parent_table)
Sample Data in Parent_table
1, 22-11-2010 00:00:00 , 'Some Title'
2, 13-11-2010 00:00:00 , 'Some Title 2'
Sample Data in Child_table
1, 1, 10
1, 2, 11
1, 8, 3
2, 5, 11
2, 8, 6
输出应返回的所有列中parent_table
与一个附加列,也就是求和的column_to_sum
值在Child_table
用于通过ID匹配在parent_table每个项目。
怎么样?
首先,尝试正确格式化代码。使用ht ecode burron 010101.另外,你的** GROUP BY **呢? – 2010-12-02 18:02:06