我正在尝试从表中过滤掉某些内容。结果应包括[时间],[第1段],[第2段..... [获胜率],[前5名PL的总和] .....等。但是,我不知道如何编码[前5位PL的总和]。如果有人可以帮助我,我将非常高兴。在此先感谢
SELECT
([Time]/500)*500 as [Time]
,[Para1]
,[Para2]
,SUM([PL]) as [Total Profit]
,AVG([PL]) as [AVERAGE]
,COUNT(*) as [Record Count]
,SUM(CASE WHEN [PL]>0 THEN 1 ELSE 0 END) as [WinCount]
,CAST (SUM(CASE WHEN [PL]>0 THEN 1 ELSE 0 END) as float) / CAST( COUNT(*) AS float) as [WINRATE]
,MIN([PL]) as [MaxDrawdown]
,MAX([PL]) as [MaxProfit]
,***************I dunno what to write here*********** [sum of top 5 PL]
,AVG(ABS(PL)) as [Average Change]
FROM [BackTest].[dbo].[HSI_SMA_VB]
GROUP BY
[Para1]
,[Para2]
,([Time]/500)*500
HAVING COUNT(*) >= 30
ORDER BY [Average] DESC
您可以使用以下内容总结前5个PL。
SELECT SUM(top_count)
FROM (
SELECT TOP(5) PL as top_count
FROM test order by top_count desc
) as t;