重复数据统计问题.
我现在得到的结果是:
SHOPID PRODUCTSNAME PRODUCTSPRICE PRODUCTS
Y001 AAA 50 1
Y001 AAA 50 1
Y002 AAA 50 1
Y002 BBB 100 1
Y002 BBB 100 1
Y003 BBB 100 1
Y003 AAA 50 1
我想要这样的结果:
SHOPID PRODUCTSNAME PRODUCTSPRICE PRODUCTS
Y001 AAA 50 2
Y002 AAA 50 1
BBB 100 2
Y003 AAA 50 1
BBB 100 1
谢谢各位高手帮帮忙!!!
------解决方案--------------------假设你上面的是表A:
select SHOPID, PRODUCTSNAME, PRODUCTSPRICE, sum(PRODUCTS) from A group by SHOPID, PRODUCTSNAME, PRODUCTSPRICE
------解决方案--------------------楼上正解。
select SHOPID, PRODUCTSNAME, PRODUCTSPRICE, sum(convert(int,PRODUCTS)) AS PRODUCTS_SUM from A group by SHOPID, PRODUCTSNAME, PRODUCTSPRICE
------解决方案--------------------select SHOPID, PRODUCTSNAME, PRODUCTSPRICE, sum(PRODUCTS) from tablename
group by SHOPID, PRODUCTSNAME, PRODUCTSPRICE
可以得到
SHOPID PRODUCTSNAME PRODUCTSPRICE PRODUCTS
Y001 AAA 50 2
Y002 AAA 50 1
Y002 BBB 100 2
Y003 AAA 50 1
Y003 BBB 100 1