Q&A about the site for developers and users of Stellar and the Stellar Distributed Exchange
CREATE TABLE #account ( id integer NOT NULL PRIMARY KEY, name varchar(64) NOT NULL, address varchar(42) NOT NULL, symbol varchar(10) NOT NULL, network varchar(10) NOT NULL, type varchar(100) NOT NULL, ); CREATE TABLE #balance ( id integer NOT NULL PRIMARY KEY, account_id integer REFERENCES #account (id) NOT NULL, amount bigint NOT NULL, currency_type varchar(100) NOT NULL, balance_type varchar(100) NOT NULL, network varchar(10) NOT NULL, ); INSERT INTO #account(id,name,address,symbol,network,type) VALUES (1,'test','test','test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (1,1,10000,'test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (2,1,10000,'test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (3,1,10000,'test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (4,2,10000,'test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (5,2,-70000,'test','test','test'); INSERT INTO #balance(id,account_id,amount,currency_type,balance_type,network) VALUES (6,2,100000,'test','test','test'); -- aggregated view of the sum of all account balances per account id SELECT account_id, sum(amount) from #balance GROUP BY account_id;