我有三个datagridviews,如图所示。好吧,我确实有,但不得不删除它们。
收入接收数据网格视图的SQL选择如下:
("Select I_Stock_Code as 'Stock Code', Income_Date, Dividend_Amount as 'Dividend Income', Franked_Income as 'Franking Credit Income', Option_Income as 'Option Income', Dividend_Amount + Option_Income + Franked_Income as 'Total Income', Notes from Income order by I_Stock_Code", JKPLConnection);
详细投资数据网格视图的SQL选择如下:
("Select B_Stock_Code as 'Stock Code', Buy_Date, Number_Bought as 'Bought',Price as 'Buy Price', Brokerage as ' Brokerage Cost', Total_Cost as 'Investment Cost', Interest_Rate as 'Opportunity Interest Rate %', Acc_interest as 'Accumulated Interest', (Total_Cost + Acc_Interest)/Number_Bought as 'Breakeven Price'FROM Buy ORDER BY B_Stock_Code", JKPLConnection);
Consolidated Investment数据网格视图的SQL选择如下:
("SELECT B_Stock_Code as 'Stock Code', COUNT (Number_Bought) as Transactions, SUM (Number_Bought) AS Bought, SUM (Total_Cost)/SUM (Number_Bought) AS 'Average Buy Price', SUM (Total_Cost) AS 'Total Investment', SUM (ACC_Interest) AS 'Opportunity Interest Cost', (SUM (Total_Cost) + SUM(ACC_Interest))/SUM (Number_Bought) AS 'Breakeven Price' FROM buy GROUP BY B_Stock_Code", JKPLConnection);
到目前为止,我很满意。我的问题是,我想进入Consolidated Investment datagridview一栏,显示每项投资产生的收入。
为了测试我的SQL命令,我尝试将它们集成到生成三个datagridviews的程序中之前使用了一个单独的程序来测试语句我在SQL Tester图像中显示了最大的努力。可以看出,为必和必拓购买的数量一次又一次地重复;显示收入的Column1提供了完全错误的数字。 ![SQL Tester] [4] 我完全不知道解决方案。这是生成视图的代码。
SELECT
Buy.B_Stock_Code AS StockCode,
SUM(buy.Number_Bought) AS NumberBought,
SUM(Buy.Total_Cost) AS TotalCost,
SUM(Buy.Acc_Interest + Buy.Total_Cost) AS TotalInvestment,
SUM(Income.Option_Income + Income.Franked_Income + Income.Option_Income)
FROM
Buy
FULL OUTER JOIN
Income ON Buy.B_Stock_Code = Income.I_Stock_Code
GROUP BY
Buy.B_Stock_Code, Income.Incomeid
ORDER BY
B_Stock_Code
我正在使用C#Microsoft Visual Studio Express 2013 for Windows Desktop。我希望这不是太多的信息,但更重要的是,它清楚地传达了我的问题。我不得不删除图像,因为我不允许上传它们。如果有人能够阐明这一点并且上面的信息还不够,我很乐意通过电子邮件发送图片。