Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:05:14+00:00 2026-05-28T05:05:14+00:00

For example, if I have a column that represent a Y or N flag,

  • 0

For example, if I have a column that represent a Y or N flag, what percentage is a Y and what percentage is an N? I know I can write a query to find each of these numbers and then calculate the percentage myself, but I figure it should be straight forward doing this in PL/SQL with analytic functions like NTILE.

SELECT COUNT(1), enabled_flag
FROM widgets
GROUP BY enabled_flag;

Gives me:

COUNT(1)   | enabled_flag
  123124   | Y
  234234   | N

I need:

enabled_flag | percentage
Y            |         34
N            |         56

Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:05:15+00:00Added an answer on May 28, 2026 at 5:05 am

    Try an analytic function as such:

    SELECT round(100*COUNT(1)/sum(count(1)) over (),0), enabled_flag
    FROM widgets
    GROUP BY enabled_flag;
    

    EDIT… you can also use the RATIO_TO_REPORT function which might make it look cleaner or easier to maintain:

    SELECT round(100*RATIO_TO_REPORT(count(1)) over (),0), enabled_flag
    FROM widgets
    GROUP BY enabled_flag;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I have an identity (unique, non-repeating) column span multiple tables? For example, let's
Anyone knows how to get sum of number? For example i have mysql column
I have a column of type Bit (called BBoolVal in this example). I have
How do I retrieve a multi-column PK in MySQL? For example I have my
I have a text column with repeated values, for example: | A | ---|---------|
In SQL Server I have a DATETIME column which includes a time element. Example:
For example, I have a table, and there is a column named 'Tags'. I
I have a list of lists that represent a grid of data (think rows
I have a flattened table that contains columns that represent groups that need to
I would like to have a primary key column in a table that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.