如何将值传递给临时表

时间:2014-04-18 07:40:37

标签: sql oracle

SELECT p1.*,
      (p1.opening_balance + p1.retained_now - p1.released_now -
       p1.clawbacked_amount - p1.arrears_amount) AS closing_balance
 FROM (SELECT p.channel_org_id,
              t.channel_name,
              p.aggregation_id,
              ((SELECT SUM(amount)
                  FROM t_agent_retention_balance
                 WHERE agent_id IN
                       (SELECT agent_id
                          FROM t_agent
                         WHERE channel_org_id = p.channel_org_id)
                   AND account_type = 5) -
               (SELECT SUM(commision)
                  FROM t_product_commision
                 WHERE aggregation_id < p.aggregation_id
                   AND channel_org_id = p.channel_org_id
                   AND commision_type_id = 1104) +
               (SELECT SUM(commision)
                  FROM t_product_commision
                 WHERE aggregation_id < p.aggregation_id
                   AND channel_org_id = p.channel_org_id
                   AND commision_type_id = 1110) +
               (SELECT SUM(commision)
                  FROM t_product_commision
                 WHERE aggregation_id < p.aggregation_id
                   AND channel_org_id = p.channel_org_id
                   AND commision_type_id = 1122) +
               (SELECT SUM(commision)
                  FROM t_product_commision
                 WHERE aggregation_id < p.aggregation_id
                   AND channel_org_id = p.channel_org_id
                   AND commision_type_id = 1123)
              ) AS opening_balance,
              (SELECT SUM(commision)
                 FROM t_product_commision
                WHERE aggregation_id = p.aggregation_id
                  AND channel_org_id = p.channel_org_id
                  AND commision_type_id = 1104) AS retained_now,
              (SELECT SUM(commision)
                 FROM t_product_commision
                WHERE aggregation_id = p.aggregation_id
                  AND channel_org_id = p.channel_org_id
                  AND commision_type_id = 1110) AS released_now,
              (SELECT SUM(commision)
                 FROM t_product_commision
                WHERE aggregation_id = p.aggregation_id
                  AND channel_org_id = p.channel_org_id
                  AND commision_type_id = 1122) AS clawbacked_amount,
              (SELECT SUM(commision)
                 FROM t_product_commision
                WHERE aggregation_id = p.aggregation_id
                  AND channel_org_id = p.channel_org_id
                  AND commision_type_id = 1123) AS arrears_amount
         FROM t_product_commision p, t_channel_org t, t_commision_type ct
        WHERE t.channel_id = p.channel_org_id
          AND p.commision_type_id = ct.commision_type_id
          AND p.aggregation_id =?
          AND p.comm_status <> 1
          AND p.channel_org_id = ?
        GROUP BY p.channel_org_id, t.channel_name, p.aggregation_id) p1

我想将值传递给? p1临时表中的参数如何实现这个 在?我希望传递p1.x的地方,如果我试图在p1之后传递像p1.x = 12这样的值 where p1.x=12 and p1.y=23它说p1.x是无效的标识符

1 个答案:

答案 0 :(得分:0)

我认为你的意思是,你只想传递不同的输入值来运行select with。 你就是这样做的:

select *
from <yourtable>
where <fieldname> = '&1';

如果您通过替换您的表名和您的字段名来运行此查询,那么您将被要求为&amp; 1提供值。 每次重复查询时,此值都可能不同。