代码之家  ›  专栏  ›  技术社区  ›  Adi

子查询中的循环日期

  •  0
  • Adi  · 技术社区  · 6 年前

    我试图得到每天的总和,并为子查询做额外的事情,不幸的是,我尝试了很多想法,真的不知道怎么做。

        SELECT
         INVOICE_DATE
        ,INVOICE_COUNT as "Number of Invoices"
        ,<here> as "Team percentage"
    FROM 
        <table_name>
    WHERE 
        user = :P2_USER 
    AND 
        invoice_date BETWEEN TO_DATE(:P2_FROM, 'MM/DD/YYYY') AND TO_DATE(:P2_TO, 'MM/DD/YYYY') ORDER BY created_date 
    

    公式如下:

    所有细节都在同一张表中

    1 回复  |  直到 6 年前
        1
  •  1
  •   samabcde    6 年前

    请尝试以下sql,若要执行此查询,您需要使用“输入日期”加入所有团队成员和单个团队成员的结果集

    SELECT individual_count.in_date,
      TO_CHAR( individual_count.sum_in_count * 100 / all_count.sum_in_count , '99.99') AS "Team percentage"
    FROM
      (SELECT SUM(IN_COUNT) AS sum_in_count,
        in_date
      FROM <in_table>
      WHERE in_date BETWEEN TO_DATE(:P2_FROM, 'MM/DD/YYYY') AND TO_DATE(:P2_TO, 'MM/DD/YYYY')
      AND username = :P2_USER
      GROUP BY in_date
      ) AS individual_count
    INNER JOIN
      (SELECT SUM(IN_COUNT) AS sum_in_count,
        in_date
      FROM <in_table>
      WHERE in_date BETWEEN TO_DATE(:P2_FROM, 'MM/DD/YYYY') AND TO_DATE(:P2_TO, 'MM/DD/YYYY')
      GROUP BY in_date
      ) AS all_count
    ON individual_count.in_date = all_count.in_date;