I would like to do a 'group by' on the following example table
- [Low] = Min of [Low] column
- [High] = Max of [High] column
- [Symbol]
- [Epoch]
- [CuVol]
- [Dt10Min])
- [Close]
- [Open]
Columns 3-7 have the values corresponding to highest Epoch, which is 129 in this case and columns 8 will be the value of [Open] at lowest Epoch of the group [Dt10Min],127 in this case.
I am very new to SQL can you please suggest.
Best Answer
I'll borrow Joe's
create table/insert
example, and assumingSymbol
is the effective PK for the final result I've thrown in a second set of data forSymbol = 'B'
:We'll create a derived table of the
max()/min()
values (grouped bySymbol
), then use the derived table'smin(Epoch)/max(Epoch)
values to perform 2 joins back to the raw data to generate our final result set:Here's a dbfiddle for the above.