how to group by, and select from two tables, need two records for each given id

后端 未结 3 1123
暖寄归人
暖寄归人 2021-01-26 13:08

I am new to SQL query. Can you please help me with the following?

table 1 QuoteObservations:

id value quotePointId asOfTime 

table 2

3条回答
  •  独厮守ぢ
    2021-01-26 14:05

    You need to remove the WHERE condition that is limiting the results on QuoteObservations.id =1 OR QuoteObservations.id = 2

    Here is the revised SQL, with that condition removed. I have also moved the JOIN conditon into the JOIN clause.

    SELECT  QuoteObservations.id, 
            QuoteObservations.value, 
            QuoteObservations.quotePointId,
            max(QuoteObservations.asOfTime) as asOfTime, 
            QuoteObservations.dataProviderId,
            QuotePoints.quoteType 
    FROM    QuoteObservations
    INNER JOIN
            QuotePoints 
    ON      QuoteObservations.quotePointId = QuotePoints.id 
    WHERE   QuotePoints.quoteType in (1,2)
    group by 
            QuoteObservations.id, 
            QuoteObservations.value, 
            QuoteObservations.quotePointId,
            QuoteObservations.dataProviderId, 
            QuotePoints.quoteType;
    

提交回复
热议问题