-2

I have a table that has rows for various stock prices at various times of the day for many different companies. Each row is a stocks price at a particular time of day. The times are not the same for each stock.

I can't figure out how to query for the price of each stock at the earliest time point.

For example, from the below example table I would want the query to return: ABC 1.25 XYZ 0.95

[Stock] [Trade Time] [Price]

ABC 9:35 1.25

ABC 9:55 1.15

ABC 10:35 1.50

XYZ 9:47 0.95

XYZ 9:53 1.00

XYZ 11:10 0.85

Epaulson2
  • 19
  • 2

1 Answers1

0

A simple method uses a correlated subquery:

select t.*
from t
where t.tradetime = (select min(t2.tradetime) from t t2 where t2.stock = t.stock);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786