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 6384091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:43:51+00:00 2026-05-25T02:43:51+00:00

Table: FooData ID Count 1 54 2 42 3 33 4 25 5 16

  • 0

Table: FooData

ID   Count
1    54
2    42
3    33
4    25
5    16
6    9
8    5
9    3
10   2

I want to fetch the record that sum of Count column is greater than a certain percentage like 90.

For this example, the sum of all the records is 189, and 90% of it is 170.1, we can see the sum from ID 1 to 6 is 179, and it is greater than 170.1 so the record ID 6 should be returned.

btw, temporary table is not allowed because I need to do it in a function.

  • 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-25T02:43:52+00:00Added an answer on May 25, 2026 at 2:43 am

    Try this:

    SELECT TOP 1 
      t2.id,
      SUM(t1.value) AS runningTotal
    FROM FooData t1 
    INNER JOIN FooData t2 
      ON t1.id <= t2.id 
    GROUP BY t2.id
    HAVING SUM(t1.value) * 100. / 
      (SELECT SUM(value) FROM @FooData) > 90
    ORDER BY SUM(t1.value)
    

    But also be aware of the potential performance issue with triangular joins in running totals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL table set that looks like this create table foo (
Table name: Employee Column Name: Emp_name Emp_name has this contents: xx\rama, xx\rajesh, xx\vignesh I
Table A has two columns: ID and name I want to input 3 ID
TABLE 1 is like following A B 1 x 2 y 3 z 4
Table is huge. For testing application I want to delete all, except 1000 records
Table locations contains locID , lat & long & name values of a certain
Table Each row represents a video that was on air at particular time on
table data of 2 columns category and subcategory i want to get a collection
Table - user_feed column name - date_n_time (type - datetime) How do I write
Table: UserId, Value, Date. I want to get the UserId, Value for the max(Date)

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.