SELECT format(nz(e.dd,0)+nz(d.dd,0),'#0.##') AS cb, *
FROM [SELECT a.正代号, b.*
FROM 代号对应表 AS a, (SELECT 余额表.币别, right(余额表.代号,4) as 代号, sum(余额表.余额) as dd
FROM 余额表 group by 余额表.币别, right(余额表.代号,4)
) AS b
WHERE b.代号=a.负代号]. AS d LEFT JOIN [SELECT 余额表.币别, right(余额表.代号,4) as 代号, sum(余额表.余额) as dd
FROM 余额表 group by 余额表.币别, right(余额表.代号,4)
]. AS e ON (d.币别=e.币别) AND (e.代号=d.正代号);
SELECT format(nz(e.dd,0)+nz(d.dd,0),'#0.##') AS cb, *
FROM [SELECT a.正代号, b.*
FROM 代号对应表 AS a, (SELECT 余额表.币别, 余额表.代号, sum(余额表.余额) as dd
FROM 余额表 group by 余额表.币别, 余额表.代号
) AS b
WHERE b.代号='0'+a.负代号]. AS d LEFT JOIN [SELECT 余额表.币别, 余额表.代号, sum(余额表.余额) as dd
FROM 余额表 group by 余额表.币别, 余额表.代号
]. AS e ON (e.代号='0'+d.正代号) AND (d.币别=e.币别);
上述代码可以将不为0的代号列出来。