说我有以下查询:
SELECT quantity
FROM TABLE A
WHERE account = xx
AND date = xxx-xx-xx
此查询返回一个值。假设我现在想在第二个查询中使用该值作为变量,如:
SELECT SUM(quantity) + variable as 'CURRENT POS'
FROM TABLE B
WHERE account = xx
AND date = xxx-xx-xx
我将如何做到这一点?
答案 0 :(得分:0)
SELECT
(SELECT SUM(quantity) FROM tb2 WHERE account = xx AND date = xxx-xx-xx) +
(SELECT SUM(quantity) FROM tb1 WHERE account = xx AND date = xxx-xx-xx)
请注意,有一百万种方法可以解决它: - )