W
W
WonderMetal2014-12-10 19:18:56
MySQL
WonderMetal, 2014-12-10 19:18:56

How to use SQL UPDATE a field on the result of a SELECT?

The essence of the question, for example, there is such a request

SELECT @sql_avrg_pulse := ((SELECT avrg_pulse FROM c_p WHERE c_id = c.id AND (created_at BETWEEN '2014-12-08 22:00:00' AND '2014-12-09 21:59:59') LIMIT 1) + calc_chall_pulse(c.id,c_p.reply_count,c_p.share_count,                
 	                     c_p.comment_count,c_p.full_view_count,
 	                     c_p.like_count,c_p.view_count))/2, 
        c.id, c.average_pulse, c.created_at  
 
 FROM c, c_p, pulse_modificators 
 WHERE pulse_modificators.id = 1 AND 
       (`c_p`.`created_at` BETWEEN '2014-12-09 22:00:00' AND '2014-12-10 21:59:59') AND
        `c_p`.`challenge_id` = `c`.`id`  LIMIT 10;

I need the @sql_avrg_pulse result to abdate the c_p.average_pulse table row with this result.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yakhnenko, 2014-12-15
@ayahnenko

update table set field = (select value from table where condition) where condition; ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question