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

  • SEARCH
  • Home
  • 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 6542823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:16:25+00:00 2026-05-25T11:16:25+00:00

refer to this question: Get count of items and their values in one column

  • 0

refer to this question:

Get count of items and their values in one column

how I can get percent of record count in single query like this:

ItemId        count          Percent
------------------------------------
   1            2              33.3
   2            0                0
   3            1              16.6
   4            3              50.0            

thanks

  • 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-25T11:16:25+00:00Added an answer on May 25, 2026 at 11:16 am

    COUNT(*) OVER() gives you the total count.

    Edit But actually you need SUM(COUNT(MyTbl.ItemID)) OVER() as you are summing the values in that column.

    SELECT Items.ItemID,
           [count] = COUNT(MyTbl.ItemID),
           [Percent] = 100.0 * COUNT(MyTbl.ItemID) / SUM(COUNT(MyTbl.ItemID)) OVER()
    FROM   (VALUES (1,'N1'),
                   (2,'N2'),
                   (3,'N4'),
                   (4,'N5')) Items(ItemID, ItemName)
           LEFT JOIN (VALUES(1),
                            (1),
                            (3),
                            (4),
                            (4),
                            (4)) MyTbl(ItemID)
             ON ( MyTbl.ItemID = Items.ItemID )
    GROUP  BY Items.ItemID
    ORDER  BY Items.ItemID  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Refer to my previous Questions: Get count of items and their values in one
Please refer to this background question. After constructing this COUNT, how would I then
I'm sure this question has been asked before, but I can't get the text
Note: In this question I'm using the term autocomplete (or iterative search) to refer
I had posted this question on superuser but didn't get a helpful response. Thought
I have updated this question(found last question not clear, if you want to refer
I refer to this question: Javascript value to PHP with Jquery I tried with
note: this question and the following answers refer to data.table versions < 1.5.3; v.
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
I have 2 files: xxxxxTest.java [ refer this ] public class xxxxxTest extends TestCase

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.