select
case when StartingIv >= 0 and StartingIv < 0.1 then '0-0.1'
when StartingIv >= 0.1 and StartingIv < 0.2 then '0.1-0.2'
when StartingIv >= 0.2 and StartingIv < 0.3 then '0.2-0.3'
when StartingIv >= 0.3 and StartingIv < 0.4 then '0.3-0.4'
when StartingIv >= 0.4 and StartingIv < 0.5 then '0.4-0.5'
when StartingIv >= 0.5 and StartingIv < 0.6 then '0.5-0.6'
when StartingIv >= 0.6 and StartingIv < 0.7 then '0.6-0.7'
when StartingIv >= 0.7 and StartingIv < 0.8 then '0.7-0.8'
when StartingIv >= 0.8 and StartingIv < 0.9 then '0.8-0.9'
when StartingIv >= 0.9 and StartingIv < 1 then '0.9-1'
when StartingIv >= 1 and StartingIv < 1.1 then '1-1.1'
else 'ELSE'
end as IvRange
, Profit
from Trades
group by case when StartingIv >= 0 and StartingIv < 0.1 then '0-0.1'
when StartingIv >= 0.1 and StartingIv < 0.2 then '0.1-0.2'
when StartingIv >= 0.2 and StartingIv < 0.3 then '0.2-0.3'
when StartingIv >= 0.3 and StartingIv < 0.4 then '0.3-0.4'
when StartingIv >= 0.4 and StartingIv < 0.5 then '0.4-0.5'
when StartingIv >= 0.5 and StartingIv < 0.6 then '0.5-0.6'
when StartingIv >= 0.6 and StartingIv < 0.7 then '0.6-0.7'
when StartingIv >= 0.7 and StartingIv < 0.8 then '0.7-0.8'
when StartingIv >= 0.8 and StartingIv < 0.9 then '0.8-0.9'
when StartingIv >= 0.9 and StartingIv < 1 then '0.9-1'
when StartingIv >= 1 and StartingIv < 1.1 then '1-1.1'
else 'ELSE'
end
select
a.IvRange, sum(Profit) as Profit
FROM
(
select
case when StartingIv >= 0 and StartingIv < 0.1 then '0-0.1'
when StartingIv >= 0.1 and StartingIv < 0.2 then '0.1-0.2'
when StartingIv >= 0.2 and StartingIv < 0.3 then '0.2-0.3'
when StartingIv >= 0.3 and StartingIv < 0.4 then '0.3-0.4'
when StartingIv >= 0.4 and StartingIv < 0.5 then '0.4-0.5'
when StartingIv >= 0.5 and StartingIv < 0.6 then '0.5-0.6'
when StartingIv >= 0.6 and StartingIv < 0.7 then '0.6-0.7'
when StartingIv >= 0.7 and StartingIv < 0.8 then '0.7-0.8'
when StartingIv >= 0.8 and StartingIv < 0.9 then '0.8-0.9'
when StartingIv >= 0.9 and StartingIv < 1 then '0.9-1'
when StartingIv >= 1 and StartingIv < 1.1 then '1-1.1'
else 'ELSE'
end as IvRange
, Profit
from Trades) a
group by IvRange
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
SQL Query Help Top 1 and Distinct? | 6 | 26 | |
Replace the integer portion in CAST with a column | 4 | 16 | |
SQL Count issue | 24 | 16 | |
is there any function in ms sql that can format date this way: yymmdd hhmmss | 2 | 9 |
Join the community of 500,000 technology professionals and ask your questions.