I don't know DB2, but in MySql you can do seomething like this:
select babloc,
if(
(select count(distinct left(BAITEM,2)) from VINBINI i where i.BABLOC = e.BABLOC) > 1,
"yes",
"no"
) as SHARED_BIN
from VINBINI e
group by BABLOC
See:
http://sqlfiddle.com/#!9/21716/8[
^]
I don't really understand topic 2. But if I see it right, you can simply create a
view[
^] on top of this query. If regular view would take too much to recalculate, you can use materialized view approach (see:
http://www.fromdual.ch/mysql-materialized-views[
^])