I have two tables:
ARB
KEY (PRIMARY KEY)
ASSIGN (NOT NECESSARILY UNIQUE)
DMC
KEY (NOT UNIQUE)
ASSIGN (NOT UNIQUE)
VALUE
I need to report all the records from ARB, and sum up the values if the keys
match OR if the keys don't match, then sum up the values where the ASSIGN
matches, but only if the ASSIGN is unique in ARB.
SELECT ARB.KEY
, ARB.ASSIGN
, COALESCE((SELECT SUM(DMC.VALUE) FROM DMC WHERE DMC.KEY = ARB.KEY)
, (SELECT SUM(DMC.VALUE) FROM DMC WHERE DMC.ASSIGN =
ARB.ASSIGN AND ...), 0)
FROM ARB;
I can't think of what to put after that AND....
I don't think it matters, but I simplified things up there. DMC is actually a
view of a table with KEY/ASSIGN and another with KEY/VALUE.
Any help is appreciated.
Thanks,
David
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users