How calculate percentage

Posted on 2008-11-03
Last Modified: 2013-11-16
I already have two complex queries returning numeric values; so, in order to get the percentage value I need to use a formula:  (query1 / query2)*100, and, could be even better applying a percentage mask&.
Question by:moralesrd
    1 Comment
    LVL 59

    Accepted Solution

    Think this should work (value is column name returned from your queries -- believe cross join will work since you only have one record/value in each -- can try outer apply also unless you can use a stored procedure then I would set each value to a @variable and then use them in calculation like I show below):
    CASE q2.[value] WHEN 0 THEN 0
    ELSE q1.[value] * 100.0/q2.[value] END AS [Percentage]
    FROM (query1) AS q1
    CROSS JOIN (query2) AS q2

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now