sql - Simple Aggregation/ joining of tables -


i have 2 tables say, , b of account_numbers. b being subset of a. how join 2 tables such add additional field in output table common elements (here account_numbers) being flagged 1 , rest 0

table account_number 11 13 15 16 17 20  table b account_number 13 16 20  output table     account flag 11  0 13  1 15  0 16  1 17  0 20  1 

select account_number, count(*)-1 flag (   select account_number     union   select account_number b ) ab group account_number; 

checkout this demo. let me know if works.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -