【发布时间】:2018-04-12 13:45:41
【问题描述】:
我正在按照这些思路写一些东西:
select fielda,fieldb,
(select sum(field1)-sum(field2) as fieldc
from tableb
where fieldid = list_of_ids[i])
from tablea
where fieldid in (list_of_ids);
在子查询中,我想使用外部 where 子句中的值。所以如果 list_of_ids 是 123,456,789,那么子查询中的 fieldid 将是 123,第二个是 456,等等。这可能吗?
【问题讨论】:
-
您使用的是哪个DBMS product? “SQL”只是一种查询语言,而不是特定数据库产品的名称。请为您正在使用的数据库产品添加标签
postgresql、oracle、sql-server、db2、... -
列,不是字段...
-
Postgres,但佩林的回答有效