在一些项目名称重新映射后,我有一个临时表,如下所示:
Item | Count
Apple | 3
Apple | 2
Orange | 4
我想浓缩成这个:
Item | Count
Apple | 5
Orange | 4
到目前为止,我尝试使用自联接是这个..
SELECT rowone.item, rowone.count, rowtwo.count
FROM temp as rowone LEFT JOIN
temp as rowtwo on rowone.item = rowtwo.item and rowone.count <> rowtwo.count
哪个给了我
Item | Count | Count
Apple | 3 | 2
Apple | 2 | 3
Orange | 4
如何添加苹果的计数并删除额外的行?
答案 0 :(得分:0)
SELECT item, sum(count) 'Count'
FROM temp
group by item