I am new to SQL query. Can you please help me with the following?
id value quotePointId asOfTime
I craeted this query, it works, but I bet there is a better and more efficient way to do it, can anyone out there help?
select q.*
from (
select QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, max(QuoteObservations.asOfTime) as asOfTime, QuoteObservations.dataProviderId, qp.quoteType
from [QuoteObservations]
inner join QuotePoints qp
on qp.id = QuoteObservations.quotePointId
where quotePointId = 1
group by QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, QuoteObservations.dataProviderId
) q
inner join (
select QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, max(QuoteObservations.asOfTime) as asOfTime, QuoteObservations.dataProviderId, qp.quoteType
from [QuoteObservations]
inner join QuotePoints qp
on qp.id = QuoteObservations.quotePointId
where quotePointId = 2
group by QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, QuoteObservations.dataProviderId
) p
on q.id = p.id
inner join (
select QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, max(QuoteObservations.asOfTime) as asOfTime, QuoteObservations.dataProviderId, qp.quoteType
from [QuoteObservations]
inner join QuotePoints qp
on qp.id = QuoteObservations.quotePointId
where quotePointId = 10
group by QuoteObservations.id, QuoteObservations.value, QuoteObservations.quotePointId, QuoteObservations.dataProviderId
) s
on s.id = p.id