2013-05-04 58 views

回答

3
SELECT product_ID, 
     COUNT(*) totalCount, 
     SUM(selling_price) total_selling_price 
FROM TableName 
GROUP BY product_ID 

输出

╔════════════╦════════════╦═════════════════════╗ 
║ PRODUCT_ID ║ TOTALCOUNT ║ TOTAL_SELLING_PRICE ║ 
╠════════════╬════════════╬═════════════════════╣ 
║   10 ║   2 ║     400 ║ 
║   11 ║   2 ║     200 ║ 
║   13 ║   1 ║     300 ║ 
╚════════════╩════════════╩═════════════════════╝ 
+1

+1正确SND不错的小提琴和格式,但你为什么要左对齐各(主要)行*第二*字? – Bohemian 2013-05-04 04:23:09

2

你需要​​。

试试这个。

select product_id, count(product_id), sum(selling_price) 
from  tablename 
group by product_id; 
0

赌它一把,而不是本地测试

SELECT product_id, 
     COUNT(product_id), 
     SUM(Amount) 
FROM yourTable 
GROUP BY product_id