sql - Truncate multiple select and update clauses into a single clause -


the below query seems inefficient, doing swapping out 1 variable (cobrand) each query. there way consolidate query 1 clause , same result?

update temp_08.members set distinct_count= (select distinct_count temp_08.members cobrand='10001372' , month = '2016-09') cobrand='10001372' , month = '2016-10' or month = '2016-11';   update temp_08.members set distinct_count= (select distinct_count temp_08.members cobrand='10006164' , month = '2016-09') cobrand='10006164' , month = '2016-10' or month = '2016-11';    update temp_08.members set distinct_count= (select distinct_count temp_08.members cobrand='10005640' , month = '2016-09') cobrand='10005640' , month = '2016-10' or month = '2016-11';    update temp_08.members set distinct_count= (select distinct_count temp_08.members cobrand='10005244' , month = '2016-09') cobrand='10005244' , month = '2016-10' or month = '2016-11'; 

use postgres' update-with-join syntax:

update temp_08.members set distinct_count = dc (select cobrand, distinct_count dc       temp_08.members       month = '2016-09') x temp_08.members.cobrand = x.cobrand , month in ('2016-10', '2016-11') 

you can add inner query if want update cobrands:

and cobrand in ('10001372', '10006164', '10005640', '10005244') 

Comments

Popular posts from this blog

php - Autoloader issue not returning Class -

python - Getting next two indexes regardless of current index -

ruby - Prevent Custom Validation Error on Association -