日期:2014-05-19  浏览次数:20439 次

连接查询中使用SUM函数求某符合条件的值
表一:test_cat   结构
cat_id             cat_name         prd_id      
    1                       test_1         1a
    2                       test_2         1b
    3                       test_3         1c
表二:test_table     结构
test_id             prd_id     value_1       value_2       value_3
    1                       1a               1                   1                   1
    2                       1a               1                   1                   1
    3                       1a               1                   1                   1
    4                       1b               2                   2                   2
    5                       1b               2                   2                   2
    6                       1c               3                   3                   3
    7                       1c               3                   3                   3

希望得到的结果为
cat_id             cat_name         prd_id       value_1       value_2       value_3
    1                       test_1         1a                   3                     3                   3
    2                       test_2         1b                   4                     4