Dupe值时,Oracle SQL PERCENT_RANK是否倾斜?

时间:2014-06-16 22:42:23

标签: sql oracle

下午好:我正在努力确定销售产品百分比的最佳方式,占销售案例(和/或美元)的80%。据报道,去年的报道为20%。我今年也得到了同样的东西,但我很担心,这似乎是我需要的销售百分比与剩下的百分比之间的直接关联。例如,如果我想要90%的销售额,那么我会获得10%的产品。

虽然这些公式似乎在下面的查询中有效,但我想知道它是否因为销售案例中的重写值而出现偏差。如果我将80%的销售案例加起来,那么产品的数量要低得多。但我不知道查询是否因为那些欺骗而倾斜,并且它给了我80%的更高价值。我还看到有一个总百分比 - 我应该尝试那个吗?

这是一个查询示例,我正在尝试一些选项以获得更合理的值。提前谢谢!

SELECT
    sales_cases,
    total_sales_cases,
    total_item_count  ,
    NVL(RowNbrCs,0) as RowNbrCs,

    PERCENT_RANK() OVER(PARTITION BY company_id  ORDER BY  (sales_cases / total_sales_cases) ASC )  as Rank_by_Cases ,
    PERCENT_RANK() OVER(PARTITION BY company_id  ORDER BY   (NVL(RowNbrCs,0) / sum(total_sales_cases)) ASC )  as Rank_by_Cases 

FROM (
    SELECT
        company_id  ,
        prod_id ,
        SUM( NVL(sales_cases,0)) ,0)  as sales_cases,
        SUM( NVL(net_sales,0)) ,0)  as net_sales,
        ROUND( SUM(( SUM( NVL(sales_cases,0)) )) OVER(PARTITION BY company_id ),0)  as total_sales_cases,
        ROUND( SUM(( SUM( NVL(net_sales,0)) )) OVER(PARTITION BY company_id ),0)  as total_net_sales,
        ROW_NUMBER() OVER(PARTITION BY company_id  ORDER BY  SUM( NVL(sales_cases,0)) ASC ) as   RowNbrCs,
        ROW_NUMBER() OVER(PARTITION BY case when company_id  ORDER BY  SUM( NVL(net_sales,0)) ASC ) as   RowNbrSls,
        SUM(( COUNT(distinct prod_id) )) OVER() as total_item_count 

    from sales, customer, product
    where << conditions >>
    group by
        company_id  ,   prod_id
)
group by    
    sales_cases ,
    total_sales_cases ,
    total_item_count ,
    RowNbrCs ,
    company_id
order by  RowNbrCs desc

0 个答案:

没有答案