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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:41:21+00:00 2026-05-22T00:41:21+00:00

I have the following code. The 3 decimal places are being displayed but the

  • 0

I have the following code. The 3 decimal places are being displayed but the average is wrong. Is there a way I can restructure the code to achieve the correct result?

with total_indi_days as
(
    SELECT COUNT(*) AS total, DATENAME(DW, DateLog) AS NameOfDay 
    FROM  Access 
    GROUP BY DATENAME(DW, DateLog) 
    --ORDER BY total DESC 
)
,total_overall_days as
(
    SELECT COUNT(*) as total_days FROM  Access
)
select str(((total * 100)/ total_days ), 7, 3) as average, total, total_days, NameOfDay 
from total_indi_days, total_overall_days

result…

|average | total | total_days | NameOfDay
| 2.000  |  29   |   1000     | Sun           
| 18.000 | 188   |   1000     | Mon             
| 15.000 | 159   |   1000     | Tues         
| 20.000 | 207   |   1000     | Wed             
| 19.000 | 194   |   1000     | Thur           
| 17.000 | 171   |   1000     | Fri             
| 5.000  |  52   |   1000     | Sat  

should be…

|average | total | total_days | NameOfDay
| 2.900  |  29   |   1000     | Sun           
| 18.800 | 188   |   1000     | Mon             
| 15.900 | 159   |   1000     | Tues         
| 20.700 | 207   |   1000     | Wed             
| 19.400 | 194   |   1000     | Thur           
| 17.100 | 171   |   1000     | Fri             
| 5.200  |  52   |   1000     | Sat  

I would also like to know if there is a easier way to get this result. The “with” is a bit much, considering I have the AVG built in function, which did not work for me maybe because I was doing the wrong thing.

  • 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-22T00:41:21+00:00Added an answer on May 22, 2026 at 12:41 am

    Change

    select str(((total * 100)/ total_days ), 7, 3) as average  to 
    

    to

    select str(((total * 100.0)/ total_days ), 7, 3) as average
    

    This way, you don’t have integer division…

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

Sidebar

Related Questions

So I have the following snippet of code: private Nullable<decimal> _excessWages; public decimal ExcessWages
I have the following test code: decimal test1 = 0.0500000000000000045656554454M; double test2 = (double)test1;
I have this line of code which rounds my numbers to two decimal places.
I have the following code: var str = 0x4000000000000000; //4611686018427387904 decimal var val =
I have the following code, I want to assign a decimal value to float
I am using the following to put decimal places when formatting an amount but
I have the following code: Decimal initialBalance; DateTime dailyDate = ctx.DailyBalances.Max(c => c.DailyDate); if
I have following code: <div class='parent'> <div class='left-child'></div> <div class=right-child></div> </div> What I want
I have following code snippet and i am trying to evaluate the time take
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.