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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:56:44+00:00 2026-05-23T16:56:44+00:00

Trying to create a query which will send me back the percentage of USER_TOT_REQS.

  • 0

Trying to create a query which will send me back the percentage of USER_TOT_REQS.

How do I get the result back with decimals?

SELECT  u.USER_NAME
    ,SUM(t.REQ_AMOUNT) as 'USER_TOTAL_AMOUNT'
    ,COUNT(t.ID) as 'USER_TOT_REQS'
    ,(COUNT(t.ID)* 100 / (Select COUNT(*) from TB__TOMBSTONES t 
    JOIN TB__USERS u 
    ON u.ID = t.CURRENT_BUYER__ID
        WHERE 1=1
        AND t.REGION__ID = 1
        AND t.OFFICE__ID = 1
        AND t.STL_ASSIGNED__ID = 8)) AS 'Percentage'
FROM TB__TOMBSTONES t 
    JOIN TB__USERS u 
    ON u.ID = t.CURRENT_BUYER__ID
WHERE 1=1
AND t.REGION__ID = 1
AND t.STL_ASSIGNED__ID = 8
GROUP BY u.USER_NAME
ORDER BY USER_TOTAL_AMOUNT DESC

Basing myself on a few examples I’ve seen on stackoverflow – 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-23T16:56:44+00:00Added an answer on May 23, 2026 at 4:56 pm

    Your counts are inversed. The outer select is less selective than the nested select (which has an additional t.OFFICE__ID = 1 predicate… (unless you forgot that in the outer select?)

    The expression should be

    (SELECT COUNT(*) ...[nested select]) * 100.0 / COUNT(t.ID) AS Percentage
    

    For increased precision, make that 100.0, but that’s probably not the main issue here… Besides that, your nested select doesn’t join on the outer select’s user. Instead, for every group, it selects all users. So even more correctly:

    (SELECT COUNT(*) from TB__TOMBSTONES t2
        -- self-join t2 to the outer user. No need to join user again
        WHERE t2.CURRENT_BUYER__ID = t.CURRENT_BUYER__ID
        AND t2.REGION__ID = 1
        AND t2.OFFICE__ID = 1
        AND t2.STL_ASSIGNED__ID = 8) * 100.0 / COUNT(t.ID) AS Percentage
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a select query which will split a column values
I'm trying to create a single query which, similar to stack overflow, will give
I am trying to execute a sql query which will create a new table
I am trying to create a query using QueryOver , which will fetch a
I am trying to create a query which will return all rows of a
I'm trying to create a efficient query which will retrieve 'projects' from a database
Im trying to create a function, that will return a mysql query, which i
I'm trying to create a MySQL query that will return all individual rows (not
Im trying to create a select command to query the database I have and
I'm trying to create a created_at query range that will capture all records created

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.