Returning columns based on various conditions in Group By I would like to do a 'group by' on the following example table

Input:


Output:



[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.
Let's start by putting your data into a temp table. For future questions you'll want to do this in the question itself so people that want to help you don't have to copy it by hand from a screenshot. I made some guesses about data types:

CREATE TABLE #input (
    Symbol VARCHAR(1) NOT NULL,
    Epoch INT NOT NULL,
    [Open] NUMERIC(9, 1) NOT NULL,
    [Close] NUMERIC(9, 1) NOT NULL,
    [High] NUMERIC(9, 1) NOT NULL,
    [Low] NUMERIC(9, 1) NOT NULL,
    CuVol INT NOT NULL,
    Dt10Min DATETIME NOT NULL
);

INSERT INTO #input
VALUES
('A', 127, 23.6, 24, 23.9, 22.8, 1600, '20100822')
, ('A', 128, 24.6, 24.1, 24.8, 23.6, 3200, '20100822')
, ('A', 129, 23.7, 24.6, 23.9, 23.5, 4800, '20100822');


Now let's write separate queries for all of the information that you want and combine them at the end. Getting the minimum value from a table is very straightforward:

SELECT MIN([Low])
FROM #input;


As is getting the maximum value from a table:

SELECT MAX([High])
FROM #input;


Carrying along column values based on the minimum or maximum of another column is more complex. Around here we call that a "greatest n per group" problem. If you just need a single row then you can use the TOP operator. SQL Server will do a TOP 1 sort which will require any extremely low memory grant. This can be helpful if your table is very large. The query below returns the row with the lowest Epoch:

SELECT TOP 1 [Open]
FROM #input
ORDER BY Epoch ASC;


We can write a very similar query to return data associated with the largest Epoch. It's also easy to select as many columns as needed:

SELECT TOP 1 Symbol, [Epoch], [CuVol], [Dt10Min], [Close]
FROM #input
ORDER BY Epoch DESC;


Now we need to combine all of the queries together to get a single result set. Each query is guaranteed to return a single row, so we might as well use CROSS JOIN. Here's the complete query:

SELECT
  highest_epoch.symbol
, highest_epoch.Epoch
, lowest_epoch.[Open]
, highest_epoch.[Close]
, min_max.High
, min_max.Low
, highest_epoch.CuVol
, highest_epoch.Dt10Min
FROM
(
    SELECT
      MIN(i.[Low]) [Low]
    , MAX(i.[High]) [High]
    FROM #input i
) min_max
CROSS JOIN 
(
    SELECT TOP 1 Symbol, [Epoch], [CuVol], [Dt10Min], [Close]
    FROM #input
    ORDER BY Epoch DESC
) highest_epoch
CROSS JOIN 
(
    SELECT TOP 1 [Open]
    FROM #input
    ORDER BY Epoch ASC
) lowest_epoch;


This query returns the results that you're looking for:

╔════════╦═══════╦══════╦═══════╦══════╦══════╦═══════╦═════════════════════════╗
║ symbol ║ Epoch ║ Open ║ Close ║ High ║ Low  ║ CuVol ║         Dt10Min         ║
╠════════╬═══════╬══════╬═══════╬══════╬══════╬═══════╬═════════════════════════╣
║ A      ║   129 ║ 23.6 ║ 24.6  ║ 24.8 ║ 22.8 ║  4800 ║ 2010-08-22 00:00:00.000 ║
╚════════╩═══════╩══════╩═══════╩══════╩══════╩═══════╩═════════════════════════╝


Without any indexes, it'll do three scans of the table but it shouldn't require sorting. That could be okay depending on the size of the table and your response time requirements. However, if you need to speed the query up you could consider adding covering indexes for each derived table or you could use a more advanced technique to do the "greatest n per group" calculations. For example, it's possible to use GROUP BY to carry along extra columns as I showed in this answer.