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

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -