Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get the total of the count

Posted on 2014-12-30
3
Medium Priority
?
99 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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Ray earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

824 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