Solved

Get the total of the count

Posted on 2014-12-30
3
92 Views
Last Modified: 2014-12-30
Hi,

I have this query

select count(*) as Total, ST.ApplicationType,
cast(((count(*) * 100.0) / 741) as DECIMAL(10,2)) as Percentage from AppRepository AP
left join SourceType ST on AP.applicationType = ST.SourceID
where AP.Retired = 0
group by AP.ApplicationType, ST.ApplicationType

Open in new window


that generate this output

Total    ApplicationType                                        Percentage 
5	Access	                                                      0.67
21	Client	                                                      2.83
1	Crystal Reports	                                     0.13
303	Distributed	                                    40.89
25	Distributed/Mainframe	                   3.37
1	Function	                                                      0.13
242	Mainframe	                                     32.66
1	Other	                                                      0.13
24	Web - External/Distributed	                   3.24
76	Web - Internal/Distributed	                  10.26
41	Web - Internal/External -  Distributed	 5.53
1	Web - Internal/Mainframe	                   0.13

Open in new window



the problem that I am having is the percentage in my query I hard coded "741"
that supose to be the total of my cound and I don't know how to get it.

In my query I have the percentage:

cast(((count(*) * 100.0) / 741) as DECIMAL(10,2)) as Percentage

cast(((count(*) * 100.0) / ?????????) as DECIMAL(10,2)) as Percentage


741 is the sum of my count how can I do this

sum(count(*)) ?????

not sure please help
0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Ray earned 500 total points
ID: 40524122
See edited code ... Note the only change if the query that replaces your hard coded number
select count(*) as Total, ST.ApplicationType,
cast(((count(*) * 100.0) / (select count(*) from AppRepository where AP.Retired = 0 ) as DECIMAL(10,2)) as Percentage 
from AppRepository AP
left join SourceType ST on AP.applicationType = ST.SourceID
where AP.Retired = 0
group by AP.ApplicationType, ST.ApplicationType

Open in new window

0
 

Author Comment

by:lulu50
ID: 40524151
Ray!!!!

Thank you for your help

it works!!!!!!!!!!!!!!!!!!!!!!!!!!
0
 

Author Closing Comment

by:lulu50
ID: 40524152
Thank you
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question