Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have been working on the below query. Basically there are two tables. Realtime_Input and Realtime_Output. When I join the two tables and take the necessary columns, I made this a view and when i query against the view I get duplicates.

What am I doing wrong? When I tested using distinct keyword, I get 60 unique rows but intermittently i get duplicates. My db is on cloud foundry cloud (postgres). Is is because of that? Please help !

select i2.key_ts_long, 
    case 
        when i2.revenue_activepower = 'NA' 
        then (-1 * CAST(io.min5_forecast as real)) 
        else (CAST(i2.revenue_activepower AS real) - CAST(io.min5_forecast as real)) 
    end as diff 
 from realtime_analytic_input i2, 
     (select i.farm_id, 
             i.key_ts_long, 
             o.min5_forecast, 
             o.min5_timestamp_seconds 
        from realtime_analytic_input i, 
             realtime_analytic_output o 
       where i.farm_id = o.farm_id 
         and i.key_ts_long = o.key_ts_long 
         and o.farm_id = 'MW1'
    ) io 
    where i2.key_ts_long = CAST(io.min5_timestamp_seconds AS bigint) 
      and i2.farm_id = io.farm_id 
      and i2.farm_id = 'MW1' 
      and io.key_ts_long between 1464738953169 and 1466457841 
    order by io.key_ts_long desc
share|improve this question
1  
This and io.key_ts_long between 1464738953169 and 1466457841 should be the other way around ( between 1466457841 and 1464738953169 ) and don't use old join style. Use INNER JOINs words – Jorge Campos Jun 20 at 23:18
    
You should ask another question and describe what you want to do, with sample data and desired results. – Gordon Linoff Jun 21 at 2:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.