答案 0 :(得分:2)
select companyname, sum(shares) as shares
from companyshares
group by companyname
答案 1 :(得分:0)
谢谢Dude ..虽然这很容易但是在写完这个查询以显示第一张表(上图上)后我很困惑..
SELECT company_PR.Comp_name, user_shares_purchase.Shares_Qty_Pur
FROM company_PR INNER JOIN user_shares_purchase
ON company_PR.Comp_ID = user_shares_purchase.Comp_ID_US
WHERE Person_ID_US = (SELECT Person_ID FROM user_register WHERE Username ='"+ username.text +"');
然后,我总结了@juergen d及以上的代码。
SELECT company_PR.Comp_name as CompanyName, SUM(user_shares_purchase.Shares_Qty_Pur) as Shares
FROM company_PR INNER JOIN user_shares_purchase
ON company_PR.Comp_ID = user_shares_purchase.Comp_ID_US
WHERE Person_ID_US = (SELECT Person_ID from user_register where Username ='"+ username.text +"')
GROUP BY company_PR.Comp_name;
谢谢...