2

I have a mysql query that look likes this

select 
    s.id, sum(history.virality)
from
    spreads s , (
                select 
                     ( ( (sum(t.likes)) + ( sum(t.comments)) ) * ( 1 / ( 1 +  s.created_at  / 3600000 ) ) )as response
                from
                    spreadstimeline t
                where
                    t.spread_id = s.id
                group by
                    DATE_FORMAT(t.created_at,'%Y-%m-%d %H')
            ) as history
group by
    s.id

Mysql return an error "Unknown column 's.created_at' in 'field list'"

is there a possible way to get s to appear in the subquery, or should i start thinking of a different query.

1 Answer 1

1

Perhaps something along these lines:

select 
    s.id, sum_virality, ( ( (sum_likes) + ( sum_comments) ) * ( 1 / ( 1 +  s.created_at  / 3600000 ) ) )as response
from spreads s
inner join (select t.spread_id, DATE_FORMAT(t.created_at,'%Y-%m-%d %H') created_date, sum(t.virality) sum_virality, sum(t.likes) sum_likes, sum(t.comments) sum_comments
            from spreadstimeline t
            where t.spread_id = s.id
            group by created_date) as history
group by
    s.id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.